Message54449
Logged In: YES
user_id=80475
A few thoughts:
* If bisect provided an optional lt argument, it would still
not be thread-safe. The code for the lt function can call
arbitrary Python code that runs through the eval-loop and is
hence subject to a thread-switch.
* An advantage of the class wrapper approach is that the
prefix function gets computed just once per word. This is
not a big deal for the specific case of [:3], but it could
be a significant benefit for other functions that are
expensive to compute (because repeated calls to bisect will
access the lt function more than once).
* My own approach to the particular use case would be to map
prefixes to a list of revwords or (revword, flag) pairs:
d = dict(abb=['abbc'], abc=['abcaa', 'abcdd', 'abcss'],
abd=['abdf'])
This gives O(1) lookup time and limits the calls to the
prefix function to once per word.
Will leave this request open as it may yet be a good idea.
My concern is that it will clutter the code and the API for
only a small benefit.
Also, I'm looking at a more general purpose solution that
would make this feature request moot. This idea is to
create a fast comparison decorator class used like this:
dwordlist = map(ComparisonDecorator(lambda x: x[:3]),
wordlist)
lp = bisect_left(dwordlist, given_rev_word)
rp = bisect_right(dwordlist, given_rev_word)
|
|
Date |
User |
Action |
Args |
2007-08-23 16:10:43 | admin | link | issue1185383 messages |
2007-08-23 16:10:43 | admin | create | |
|