Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to make a hash that stores data based on a index value range instead of a single index value.

This should help explain what I mean:
________________________________________________<br />
<br />
=== PSEUDO CODE ===<br />
/* function: hash_insert(int lower_bound, int upper_bound, string data); */<br />
<br />
hash_insert(4, 11, "found me!");<br />
hash_insert(16, 19, "where am I?");<br />
<br />
print( hash_find(18) );<br />
print( hash_find(5) );<br />
<br />
=== PROGRAM OUTPUT ===<br />
where am I?<br />
found me!<br />
________________________________________________<br />


There isn't a particular pattern to the value ranges.

I'm stumped. Does anyone have a clue? :((
Posted
Updated 30-Nov-10 16:19pm
v3

Depending on the amount of potential entries and the size of the ranges, you might consider to go a brute-force approach:

--> Add for each number in the hash_insert(...) range a dedicated entry in the hash table.

I.e. the hash_insert(...) function is a convenience function for multiple consecutive single_hash_insert(...) calls.

May sound silly, but maybe it solves your problem.

Cheers

Andi
 
Share this answer
 
Is this what you're looking for?
It basically checks whether data written to the function falls in range of the saved data.

hash_insert(int lower_bound, int upper_bound, string data)
{
  static int saved_range_lower;
  static int saved_range_upper;
  if (data.Contains("?") == true)
  {
    saved_range_lower = lower_bound;
    saved_range_upper = upper_bound;
  }
  else
  {
    if((lower_bound >= saved_range_lower) &&
       (lower_bound <= saved_range_upper) &&
       (upper_bound >= saved_range_lower) &&
       (upper_bound <= saved_range_upper))
    {
      data = "found me!";
    }
    else
    {
      data = "where am I?"
    }
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900