durusmail: durus-users: btree.has_key() ?
btree.has_key() ?
2005-07-04
2005-07-06
2005-07-06
btree.has_key() ?
Mario Ruggier
2005-07-06
On Jul 6, 2005, at 4:00 PM, David Binger wrote:
> On Jul 4, 2005, at 1:29 AM, Mario Ruggier wrote:
>
>> Hi,
>>
>> would there be a better way to check if a btree contains a given key,
>> that would be better than doing:
>>
>>     key in btree.keys()
>>
>> What seems costly is the underlying btree.iterkeys() that loops over
>> the items... and maybe this is what would need to be modified.
>>
>> Is this operation an inevitably expensive one?
>>
>
> Use "key in btree" instead of "key in btree.keys()"
>
> The BTree.__contains__() method does a fast search,
> without the full iteration of keys.

Ah, yes, thanks. It makes a remarkable difference!

mario

reply