Okay, so this is a little hard to explain, but here goes:
I have a dictionary, which I\'m adding content to. The content is a hashed username (key) with an IP address (v
As seen in the OrderedDict source code, if you have a key and you want to find the next and prev in O(1) here's how you do that.
>>> from collections import OrderedDict
>>> d = OrderedDict([('aaaa', 'a',), ('bbbb', 'b'), ('cccc', 'c'), ('ffffdd', 'd'), ('eeee', 'e'), ('ffff', 'f')])
>>> i = 'eeee'
>>> link_prev, link_next, key = d._OrderedDict__map['eeee']
>>> print 'nextKey: ', link_next[2], 'prevKey: ', link_prev[2]
nextKey: ffff prevKey: ffffdd
This will give you next and prev by insertion order. If you add items in random order then just keep track of your items in sorted order.