An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

github.com/google/orderedcode

Package orderedcode provides a byte encoding of a sequence of typed items. The resulting bytes can be lexicographically compared to yield the same ordering as item-wise comparison on the original sequences. More precisely, suppose: Then comparing A versus B lexicographically is the same as comparing the vectors [A_1..A_n] and [B_1..B_n] lexicographically. Furthermore, if i < j then [A_1..A_i]'s encoding is a prefix of [A_1..A_j]'s encoding. The order-maintaining and prefix properties described above are useful for generating keys for databases like Bigtable. Call Append(buffer, item1, ..., itemN) to construct the encoded bytes. The valid item types are: As a convenience, orderedcode.Infinity is a value of type struct{}. For example, to encode a sequence of two strings, an 'infinity' and an uint64: Alternatively, encoding can be done in multiple steps: Call Parse(encoded, &item1, ..., &itemN) to deconstruct an encoded string. The valid argument types are the pointers to the valid encoding types. For example: Alternatively: A TrailingString is a string that, if present, must be the last item appended or parsed. It is not mandatory to use a TrailingString; it is valid for the last item to be a standard string or any other type listed above. A TrailingString simply allows a more efficient encoding while retaining the lexicographic order-maintaining property. If used, you cannot append a TrailingString and parse the result as a standard string, or as a StringOrInfinity. For example: The same sequence of types should be used for encoding and decoding (although StringOrInfinity can substitute for either a string or a struct{}, but not for a TrailingString). The wire format is not fully self-describing: "\x00\x01\x04\x03\x02\x00\x01" is a valid encoding of both ["", "\x04\x03\x02"] and [uint64(0), uint64(4), uint64(0x20001)]. Decoding into a pointer of the wrong type may return corrupt data and no error. Each item can optionally be encoded in decreasing order. If the i'th item is and the lexicographic comparison of A and B comes down to A_i versus B_i, then A < B will equal A_i > B_i. To encode in decreasing order, wrap the item in an orderedcode.Decr value. To decode, wrap the item pointer in an orderedcode.Decr. For example: Each item's ordering is independent from other items, but the same ordering should be used to encode and decode the i'th item.

Ecosystem
proxy.golang.org
Latest Release
v0.0.1
about 7 years ago
Versions
1
Dependent Packages
3,839
Dependent Repos
2,119
Links
Registry proxy.golang.org
Source Repository
Docs Documentation
JSON API View JSON
CodeMeta codemeta.json
Package Details
PURL pkg:golang/github.com/google/orderedcode
spec
License Apache-2.0
Namespace github.com/google
First Release about 7 years ago
Last Synced 11 days ago
Repository
Stars 41 on GitHub
Forks 12 on GitHub
Docker Dependents 269
Docker Downloads 224,069
Rankings on proxy.golang.org
Overall Top 2.6%
Dependent packages Top 0.1%
Dependent repos Top 0.2%
Forks Top 5.6%
Docker downloads Top 0.7%