sonic-pi
https://github.com/sonic-pi-net/sonic-pi
C++
Code. Music. Live.
Rugged.minimize_oid
Iterate through +oid_iterator+, which should yield any number of SHA1 OIDs
(represented as 40-character hexadecimal strings), and tries to minify them.
Minifying a set of a SHA1 strings means finding the shortest root substring
for each string that uniquely identifies it.
If no +block+ is given, the function will return the minimal length as an
integer value:
oids = [
'd8786bfc974aaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
'd8786bfc974bbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
'd8786bfc974ccccccccccccccccccccccccccccc',
'68d041ee999cb07c6496fbdd4f384095de6ca9e1',
]
Rugged.minimize_oids(oids) #=> 12
If a +block+ is given, it will be called with each OID from +iterator+
in its minified form:
Rugged.minimize_oid(oids) { |oid| puts oid }
produces:
d8786bfc974a
d8786bfc974b
d8786bfc974c
68d041ee999c
The optional +min_length+ argument allows you to specify a lower bound for
the minified strings; returned strings won't be shorter than the given value,
even if they would still be uniquely represented.
Rugged.minimize_oid(oids, 18) #=> 18Edit
git clone [email protected]:sonic-pi-net/sonic-pi.git
cd sonic-pi
open app/server/ruby/vendor/rugged-1.7.1/ext/rugged/rugged.c
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-Rugged-minimize_oid-for-pr
# Commit to gitgit add app/server/ruby/vendor/rugged-1.7.1/ext/rugged/rugged.cgit commit -m "better docs for Rugged.minimize_oid"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-Rugged-minimize_oid-for-pr
hub pull-request
# Celebrate!