I have a database in which I’d like to store an arbitrary ordering for a particular element. The database in question doesn’t support order sets, so I have to do this myself.
One way to do this would be to store a float value for the element’s position, and then take the average of the position of the surrounding elements when inserting a new one:
Item A - Position 1
Item B - Position 1.5 (just inserted).
Item C - Position 2
Now, for various reasons I don’t wish to use floats, I’d like to use strings instead. For example:
Item A - Position a
Item B - Position aa (just inserted).
Item C - Position b
I’d like to keep these strings as short as possible since they will never be “tidied up”.
Can anyone suggest an algorithm for generating such string as efficiently and compactly as possible?
Thanks,
Tim
It would be reasonable to assign ‘am’ or ‘an’ position to Item B and use binary division steps for another insertions.
This resembles 26-al number system, where ‘a’..’z’ symbols correspond to 0..25.
Pseudocode for binary tree structure: