James Tauber

journeyman of some

blog > 2005 > 07 > 19 >

Indexing Time

Dave Warnock and I have been talking about indexing entries in Leonardo by last updated time.

We want to be able to retrieve the entries between A and B, or the n entries after A or the n entries before B where A and B can be either ordinals or times.

I'm guessing the right way of doing it would be some sort of balanced tree.

The nature of the data is that insertions will almost entirely be at the end, retrieval will largely be at the end and deletions will probably be fairly distributed.

Just as a preliminary, I've written an unbalanced tree, although I haven't finished implementing the kinds of queries we want to be able to do on the tree.

Any suggestions on algorithms and/or implementations in Python?

Most implementations don't seem to come out of the box with the kind of "slice" queries we want to do (or even both key- and ordinal-based queries).

Categories:
prev « python » next
prev « leonardo » next
algorithms » next

Comments (1)

Bruce Cropley on Nov. 14, 2005:

If you don't know about them already, you might want to have a look at AVL trees and/or Red-Black trees. I think I've seen a python AVL tree module implementation floating around. I'm not sure if either of these can support ordinal queries, I'm speaking off the top of my head.

If you can get an iterator back from a search for A then it should be possible to wrap it in an iterator interface that returns the next N, or the items less than B.

Add a Comment

Created: July 19, 2005
Last Modified: July 19, 2005
Author: jtauber