01-14-2008, 01:45 AM
I have a hash table keyed on a floating point number (a molecular weight). I need to pick out all the elements who's keys fall within a certain range.
For instance, these might be the keys:
100.1
100.3
100.8
101.2
101.6
102.3
.
.
105.0
And I need to pick out all the elements that fall between say 101 and 103.
I've created a list of keys and sorted it, but I still can't figure out how to pick out the keys (and thus their indices) so that I can get at the elements in the table. I guess I could iterate over the entire list of keys, checking each to see if it fell within the range (and stopping once I'm out of the range), but this seems inefficient.
Sorry if I'm not explaining this well.
I'm using Python, but it shouldn't matter.
Thanks.
For instance, these might be the keys:
100.1
100.3
100.8
101.2
101.6
102.3
.
.
105.0
And I need to pick out all the elements that fall between say 101 and 103.
I've created a list of keys and sorted it, but I still can't figure out how to pick out the keys (and thus their indices) so that I can get at the elements in the table. I guess I could iterate over the entire list of keys, checking each to see if it fell within the range (and stopping once I'm out of the range), but this seems inefficient.
Sorry if I'm not explaining this well.
I'm using Python, but it shouldn't matter.
Thanks.