Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(examples): add package cford32, add method seqid.ID.String #1572

Merged
merged 6 commits into from
Feb 22, 2024

Conversation

thehowl
Copy link
Member

@thehowl thehowl commented Jan 23, 2024

This PR adds a new package to examples, cford32, meant primarily to be used in package seqid as an AVL- and human-friendly ID, which implements an encoding scheme with the base32 encoding scheme specified by Douglas Crockford. It additionally implements a uint64 encoding scheme I created, which encodes "tiny" (< 17 billion) values as 7-byte strings, and can encode the full uint64 range with 13 bytes.

The package is largely a fork of Go's encoding/base32, intentionally forked to have a very familiar API, while needing to be forked to implement some distinctive features of the encoding (like case insensitivity, and mapping in decoding all of the symbols l L i I 1 to the same value).

The necessity of this package comes from a solution that I implemented in GnoChess:

https://github.com/gnolang/gnochess/blob/9aa813fbb86fec377a85fc4528411d652fc780ff/realm/chess.gno#L286-L295

Essentially, GnoChess used simple sequential IDs for its saved entities (like games). To work well with AVL's sorted keys, it padded the generated strings to the left with up to 9 zeroes. This, of course, breaks for values >= 1e10 (10 billion), as ("2" + "000000000") > ("10" + "000000000").

@thehowl thehowl added the 🧾 package/realm Tag used for new Realms or Packages. label Jan 23, 2024
@thehowl thehowl self-assigned this Jan 23, 2024
@thehowl thehowl requested a review from moul as a code owner January 23, 2024 12:41
Copy link

codecov bot commented Jan 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0b39151) 44.31% compared to head (c674b37) 47.41%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1572      +/-   ##
==========================================
+ Coverage   44.31%   47.41%   +3.10%     
==========================================
  Files         438      385      -53     
  Lines       66019    61319    -4700     
==========================================
- Hits        29255    29074     -181     
+ Misses      34341    29826    -4515     
+ Partials     2423     2419       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

thehowl added a commit that referenced this pull request Jan 23, 2024
Pull request #1572 marks the codeowner as @moul, in spite of what the
configuration might suggest to a human reader.

[Reading through GitHub's
docs](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#example-of-a-codeowners-file),
this seems to come from the fact that if directories are not prefixed
with a `/`, they are considered as applying to all files or directories
with that name. (ie. `foo` matches `/foo` but also `/src/foo`).

I've added `/` to all directories in CODEOWNERS to fix this.
@github-actions github-actions bot added the 📦 🌐 tendermint v2 Issues or PRs tm2 related label Jan 26, 2024
leohhhn pushed a commit to leohhhn/gno that referenced this pull request Jan 31, 2024
Pull request gnolang#1572 marks the codeowner as @moul, in spite of what the
configuration might suggest to a human reader.

[Reading through GitHub's
docs](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#example-of-a-codeowners-file),
this seems to come from the fact that if directories are not prefixed
with a `/`, they are considered as applying to all files or directories
with that name. (ie. `foo` matches `/foo` but also `/src/foo`).

I've added `/` to all directories in CODEOWNERS to fix this.
Copy link
Member

@zivkovicmilos zivkovicmilos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great 💯

Not much to add in terms of reviewing, the package looks solid. Thank you for adding a new example package 🙏

tm2/pkg/std/memfile.go Outdated Show resolved Hide resolved
@thehowl thehowl merged commit 16c7c2e into master Feb 22, 2024
189 of 191 checks passed
@thehowl thehowl deleted the dev/morgan/cford32 branch February 22, 2024 18:24
leohhhn pushed a commit to leohhhn/gno that referenced this pull request Feb 29, 2024
…olang#1572)

This PR adds a new package to examples, `cford32`, meant primarily to be
used in package `seqid` as an AVL- and human-friendly ID, which
implements an encoding scheme with the base32 encoding scheme [specified
by Douglas Crockford](https://www.crockford.com/base32.html). It
additionally implements a `uint64` encoding scheme I created, which
encodes "tiny" (< 17 billion) values as 7-byte strings, and can encode
the full `uint64` range with 13 bytes.

The package is largely a fork of Go's `encoding/base32`, intentionally
forked to have a very familiar API, while needing to be forked to
implement some distinctive features of the encoding (like case
insensitivity, and mapping in decoding all of the symbols `l L i I 1` to
the same value).

The necessity of this package comes from a solution that I implemented
in GnoChess:


https://github.com/gnolang/gnochess/blob/9aa813fbb86fec377a85fc4528411d652fc780ff/realm/chess.gno#L286-L295

Essentially, GnoChess used simple sequential IDs for its saved entities
(like games). To work well with AVL's sorted keys, it padded the
generated strings to the left with up to 9 zeroes. This, of course,
breaks for values `>= 1e10` (10 billion), as `("2" + "000000000") >
("10" + "000000000")`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related 🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: Done
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants