f4b6a3 / uuid-creator

UUID Creator is a Java library for generating Universally Unique Identifiers.
MIT License
432 stars 44 forks source link

Add new base-n codecs for base-36, base-58 and base-62 #39

Closed fabiolimace closed 3 years ago

fabiolimace commented 3 years ago

List of new alphabets (char sets):

The alphabet for base-58 is the same used in Bitcoin.

fabiolimace commented 3 years ago

Created codecs for base-36, base-58 and base-62.

Also created static methods for codecs of any radix between 2 and 64.

List of changes:

Add Base36Codec Add Base58Codec Add Base58BitcoinCodec // Bitcoin's base-58 Add Base58FlickrCodec // Flickr's base-58 Add Base62Codec Add BaseNCodec.getInstance() // static factory for any radix between 2 and 64 Add test cases for base-16, base-32 and base-64 with 3k samples Add test cases for base-36, base-58 and base-62 with 3k samples

Test coverage: 90.0%

Benchmark for base-n codecs:

------------------------------------------------------------------
Benchmark                  Mode  Cnt      Score     Error   Units
------------------------------------------------------------------
Throughput.decode_base16  thrpt    5   4695,920 ±   6,835  ops/ms
Throughput.decode_base32  thrpt    5   2146,940 ±  26,668  ops/ms
Throughput.decode_base64  thrpt    5   2566,964 ±  25,757  ops/ms
Throughput.decode_base36  thrpt    5    528,938 ±   3,441  ops/ms *
Throughput.decode_base58  thrpt    5    609,171 ±   8,800  ops/ms *
Throughput.decode_base62  thrpt    5    629,332 ±   2,297  ops/ms *
------------------------------------------------------------------
Throughput.encode_base16  thrpt    5  18432,630 ± 171,769  ops/ms
Throughput.encode_base32  thrpt    5  20345,201 ± 126,980  ops/ms
Throughput.encode_base64  thrpt    5  21841,282 ±  43,678  ops/ms
Throughput.encode_base36  thrpt    5    267,618 ±  22,657  ops/ms *
Throughput.encode_base58  thrpt    5    243,444 ±  20,533  ops/ms *
Throughput.encode_base62  thrpt    5    257,363 ±  14,720  ops/ms *
------------------------------------------------------------------

(*) The new codecs don't perform as well as the others because the new
ones do integer arithmetic on BigInteger objects.