String coding of primitive types preserving lexicographical order

Does anyone know a library for encoding a number of primitive types (such as integers, floats, strings, etc.) into a string, but keeping the lexicographic order of the types?

Ideally, I am looking for a C ++ library, but other languages ​​are wonderful too. In addition, it can be assumed that the format does not have to be encoded in the string itself (that is, if int64 / string / float, then the encoded string does not need to be encoded for this information, only data encoding is enough).

+5
source share
4 answers
+9

longs , . Java, .

:

  • (toEncode ^ Long.MAX_VALUE ), .
  • base64 . , base64 ; (+ /) , . ASCII. ASCII. ( , base64, - _ ~ . URL-, , ).
+2

... Amazon Web Service SimpleDB . . AWS . , , apriori (, ). , .

. " 201: Amazon SimpleDB" - http://aws.amazon.com/articles/1232

http://typica.s3.amazonaws.com/com/xerox/amazonws/sdb/DataUtils.html

+2

Just write the numeric values ​​in a fixed column width with leading zeros, and the rows as usual. So like this:

0.1 -> 0000000.1000000
123 -> 0000123.0000000
foo -> foo
X   -> X

Then you can sort as text (e.g. Unix sortwithout -n). How about this?

0
source

All Articles