https://github.com/neilvallon/shortening
Fat free URLs
https://github.com/neilvallon/shortening
base64 base64url bijective encoder go url-shortener
Last synced: about 1 year ago
JSON representation
Fat free URLs
- Host: GitHub
- URL: https://github.com/neilvallon/shortening
- Owner: neilvallon
- License: mit
- Created: 2014-12-18T23:32:26.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2019-04-22T13:03:11.000Z (about 7 years ago)
- Last Synced: 2024-06-21T04:25:42.676Z (almost 2 years ago)
- Topics: base64, base64url, bijective, encoder, go, url-shortener
- Language: Go
- Homepage:
- Size: 28.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Shortening
A bijective base64 encoder for creating short URLs.
## Padding significant
Most encoders use decimal bases to convert characters.
This can waste space by refusing to use the zero-value in the most significant position.
For example, in base10 the numbers **1**, **01**, **00001**,
are all equivalent despite being padded with leading 0's.
This is why non-bijective encoders will skip values such as **A** and **AAA**
in favor of possibly longer strings.
By using these values we can recover 64(n-1) IDs
of length *n*.
| Length | Radix64 | Shortening | difference |
|--------|--------------------|---------------|------------|
| 1 | 63 | 64 | 1 |
| 2 | 4,032 | 4,096 | 64 |
| 3 | 258,048 | 262,144 | 4096 |
| 4 | 16,515,072 | 16,777,216 | 262,144 |
| 5 | 1,056,964,608 | 1,073,741,824 | 16,777,216 |
## Performance
| Benchmark | ns/op |
|--------------|--------|
| Encode64 | 46.2 |
| Decode64 | 21.6 |
| Encode32 | 46.4 |
| Decode32 | 23.7 |
* go1.12.4 darwin/amd64
* Intel Xeon X5675 - 3.06 GHz
## References
Wikipedia: [Bijective numeration](https://en.wikipedia.org/wiki/Bijective_numeration)