Mark Guzdial wrote:
> For these issues of reverse lookup and the like, it seems to me that
> the fastest and most elegant solution may be a set of Dictionaries
> that point to the same pages -- each Dictionary offers a different
> index (page number, page title, etc.) into the objects. Average
> access time will be faster than having to do a search on any index.
I've always thought that it would be neat to have a class that could
maintain such indexes on a collection. Adding objects to instances of this
class would extract information for each of the indices (based on blocks
perhaps). Removing an object would also remove it from each index. Also,
you could turn indexing on or off to do rapid insertion or deletion of
objects.
Some example methods:
addIndex: [ :obj | obj id ] called: #id
addIndex: [ :obj | obj name ] called: #name allowCollisions: true
at: 1 inIndex: #id
at: 'Page Name' inIndex: #name ifAbsent: []
rebuildIndexes
stopIndexing
startIndexing
Alternatively, instead of using blocks, maybe you could restrict it such
that you just supply a unary selector, and let that be the both the index
name and the method for key retrieval.
- Stephen