GitOidShorten.add

Add a new hex OID to the set of shortened OIDs and store the minimal length to uniquely identify all the OIDs in the set. This length can then be retrieved by calling minLength.

Note: The hex OID must be a 40-char hexadecimal string. Calling add with a shorter OID will throw a GitOid exception.

For performance reasons, there is a hard-limit of how many OIDs can be added to a single set - around ~22000, assuming a mostly randomized distribution.

Attempting to go over this limit will throw a GitException.

struct GitOidShorten
void
add
(
in char[] hex
)

Examples

1 auto sh = GitOidShorten(5);
2 assert(sh.minLength == 5);
3 
4 sh.add("1234000000000000000000000000000000000000");
5 assert(sh.minLength == 5);
6 
7 sh.add("1234500000000000000000000000000000000000");
8 assert(sh.minLength == 5);
9 
10 // introduce conflicting oid which requires a
11 // larger length for unique identification in the set
12 sh.add("1234560000000000000000000000000000000000");
13 assert(sh.minLength == 6);
// adding a shortened hex is disallowed
auto sh = GitOidShorten(5);
assertThrown!GitException(sh.add("1234"));

Meta