As others have pointed out, it is impractical to do what you requested. You should use this string as a hash that limits the length of strings that could be "hashed", etc.
An obvious approach to preserving a “sorted hash” data structure would be to support both a sorted list (such as a heap and a binary tree) and hashed data mapping. The insertions and deletions will be O (log (n)), while the samples will be O (1). I'm not sure how often it will cost extra complexity and overhead.
If you had a particularly large dataset, mostly read-only and such that the logarithmic time search was too expensive, I think this might be useful. Note that the cost of updates is actually the sum of the constant (hash) time and logarithmic time operations (binary tree or heap). However, O (1) + O (log (n)) reduces to the larger of the two terms in asymptotic analysis. (The underlying cost still exists - applicable to any implementation effort, regardless of its theoretical inconsistency).
For a significant range of data set sizes, the cost of maintaining this hypothetical hybrid data structure can be estimated as "twice as much" the cost of maintaining any of the clean ones. (In other words, many binary tree implementations can scale to billions of elements (2 ^ ~ 32 or so) in time, which is comparable to the cost of typical hash functions). Therefore, it would be difficult for me to convince myself that such added code complexity and time cost (hybrid data structure) would really be useful for this project.
(Note: I saw that Python 3.1.1 added the concept of “ordered” dictionaries ... and it looks like sorting, but not quite the same. From what I collect, an ordered dictionary preserves the order in which the elements were added to collection. I also seem to remember some talk of “views” ... objects in the language that somehow can access the keys of the dictionary (sort, reverse, reverse sort, ...) at a (possibly) lower cost than transmitting a set of keys through the built-in "sorted ()" and "reverse" ("). I do not use I used them and didn’t look at the implementation details. I would suggest that one of these "views" would look like a lazily evaluated index, performing the necessary sorting by call and saving the results with some flag or trigger (observer or listener template) that reset when the original collection of sources is updated, so that the “presentation” call scheme updates its index, subsequence calls will be able to use these ts results if no insertions or deletions were made in the dictionary. Any appeal to the view after changing the key will lead to the cost of updating the view. However, this is all pure reflection on my part. I mention this because it can also give an idea of some alternative ways of approaching the issue).
Jim dennis
source share