From 29167a4a18c43491ff459c811b87a6cfc9ecb0e7 Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Sat, 14 Feb 2026 14:40:31 -0600 Subject: [PATCH 1/3] test: Add more tests for base30 encoding --- test/Base30.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/Base30.jl b/test/Base30.jl index 6de61d3..97cd736 100644 --- a/test/Base30.jl +++ b/test/Base30.jl @@ -17,5 +17,8 @@ end #@testset @testset "base30encode" begin @test base30encode(0) == "0" @test base30encode(1) == "1" + @test base30encode(29) == "Z" @test base30encode(30) == "10" + @test base30encode(31) == "11" + @test base30encode(59) == "1Z" end From b4c60874e1fdc5d4ab743419766153973e348ec8 Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Sat, 14 Feb 2026 14:41:26 -0600 Subject: [PATCH 2/3] perf: Replace rebase function with call to built-in digits function --- src/Base30.jl | 54 +------------------------------------------------ src/CualerID.jl | 1 - test/Base30.jl | 14 ------------- 3 files changed, 1 insertion(+), 68 deletions(-) diff --git a/src/Base30.jl b/src/Base30.jl index be15aa4..9bc673e 100644 --- a/src/Base30.jl +++ b/src/Base30.jl @@ -26,53 +26,6 @@ const BASE30_ALPHABET = UInt8.([ 87:90..., #W-Z ]) -""" - rebase(v::Integer, base::Integer) - -Rebase `v` into the base system of `base`. `v` can be any integer type, and can -be represented in base 10 (decimal) or base 16 (hexadecimal) based on Julia's -treatment of that integer type. Returns a `Vector{UInt8}` containing the -**indices** of each digit in the rebased number. Since Julia is 1-indexed, this -means that `rebase(0, base)[1]` actually returns a value of `UInt8[1]`, since -the first index of a numeral system's alphabet is assumed to be its ``0`` value. - -# Examples - -```jldoctest -julia> rebase(0, 10) -1-element Vector{UInt8}: - 0x01 - -julia> # Two plus two is ten... IN BASE FOUR! I'M FINE! - -julia> rebase(2 + 2, 4) -2-element Vector{UInt8}: - 0x02 - 0x01 - -julia> base_4_alphabet = ['0', '1', '2', '3']; - -julia> String([base_4_alphabet[i] for i in rebase(2 + 2, 4)]) -"10" -``` - -!!! warning - - This method is not tested on negative integers and may produce incorrect - output when passed negative numbers -""" -function rebase(v::Integer, base::Integer) - remainder = UInt8((v % base) + 1) - quotient = div(v, base) - - if quotient == 0 - return [remainder] - else - return [rebase(quotient, base)..., remainder] - end #if - -end #function - """ base30encode(v::Integer) base30encode(v::UUID) @@ -91,14 +44,9 @@ julia> base30encode(30) julia> using UUIDs; base30encode(uuid1()) "7ZK00JECBDF2H7GNBXN59C6S9S" ``` - -!!! warning - - Just like [`rebase`](@ref), this method is not tested on negative integers - and may produce incorrect output when passed negative numbers """ function base30encode(v::Integer) - return String([BASE30_ALPHABET[i] for i in rebase(v, 30)]) + return String([BASE30_ALPHABET[i] for i in reverse(digits(v; base = 30) .+ 1)]) end #function function base30encode(v::UUID) diff --git a/src/CualerID.jl b/src/CualerID.jl index 08879b2..d8645f9 100644 --- a/src/CualerID.jl +++ b/src/CualerID.jl @@ -14,7 +14,6 @@ export has_duplicate export has_fixed export has_not_fixable export has_valid -export rebase function _create_arg_table() s = ArgParseSettings(autofix_names = true) diff --git a/test/Base30.jl b/test/Base30.jl index 97cd736..f4b120b 100644 --- a/test/Base30.jl +++ b/test/Base30.jl @@ -1,19 +1,5 @@ using CualerID: base30encode, rebase -@testset "rebase" begin - @test rebase(0, 10) == UInt8[1] - @test rebase(0, 2) == UInt8[1] - @test rebase(0, 32) == UInt8[1] - - @test rebase(10, 10) == UInt8[2, 1] - @test rebase(2, 2) == UInt8[2, 1] - @test rebase(32, 32) == UInt8[2, 1] - - @test rebase(11, 10) == UInt8[2, 2] - @test rebase(3, 2) == UInt8[2, 2] - @test rebase(33, 32) == UInt8[2, 2] -end #@testset - @testset "base30encode" begin @test base30encode(0) == "0" @test base30encode(1) == "1" From 031dbf06c95a3a0f6f273f05085d8aeac82e6a63 Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Sat, 14 Feb 2026 14:53:23 -0600 Subject: [PATCH 3/3] feat: Add _hamming function --- src/CualerID.jl | 1 + src/Minting.jl | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 src/Minting.jl diff --git a/src/CualerID.jl b/src/CualerID.jl index d8645f9..013a135 100644 --- a/src/CualerID.jl +++ b/src/CualerID.jl @@ -6,6 +6,7 @@ using UUIDs: UUID include("Base30.jl") include("ResultCodeOption.jl") +include("Minting.jl") export ResultCode export ResultCodeOption diff --git a/src/Minting.jl b/src/Minting.jl new file mode 100644 index 0000000..ede65d3 --- /dev/null +++ b/src/Minting.jl @@ -0,0 +1,11 @@ +""" + _hamming(str1::AbstractString, str2::AbstractString) + +Computes the [Hamming distance](https://en.wikipedia.org/wiki/Hamming_distance) between +`str1` and `str2`. +""" +function _hamming(str1::AbstractString, str2::AbstractString) + length(str1) != length(str2) && + throw(DimensionMismatch("strings must be of equal length")) + return sum(c -> first(c) != last(c), zip(str1, str2)) +end #function