New Upstream Snapshot - golang-github-martinlindhe-base36

Ready changes

Summary

Merged new upstream version: 1.1.1+git20221101.1.9c25352 (was: 1.0.0).

Resulting package

Built on 2022-11-21T02:42 (took 4m28s)

The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:

apt install -t fresh-snapshots golang-github-martinlindhe-base36-dev

Lintian Result

Diff

diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 173a930..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,12 +0,0 @@
-language: go
-
-go:
-  - 1.11.x
-  - 1.12.x
-  - tip
-
-before_install:
-  - go get -t ./...
-
-script:
-  - go test -v
diff --git a/LICENSE b/LICENSE
index c75ced8..4082ac8 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
 The MIT License (MIT)
 
-Copyright (c) 2015-2019 Martin Lindhe
+Copyright (c) 2015-2021 Martin Lindhe
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
diff --git a/Makefile b/Makefile
deleted file mode 100644
index abf174a..0000000
--- a/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-bench:
-	go test -benchmem -bench=.
-
-test:
-	go test -v
diff --git a/README.md b/README.md
index 1d31eae..8d5b6e1 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,5 @@
 # About
 
-[![Travis-CI](https://api.travis-ci.org/martinlindhe/base36.svg)](https://travis-ci.org/martinlindhe/base36)
 [![GoDoc](https://godoc.org/github.com/martinlindhe/base36?status.svg)](https://godoc.org/github.com/martinlindhe/base36)
 
 Implements Base36 encoding and decoding, which is useful to represent
@@ -24,6 +23,10 @@ fmt.Println(base36.DecodeToBytes("A2F44"))
 // Output: [1 2 3 4]
 ```
 
+## Notice
+
+For basic base 36 conversion, you can use [strconv.FormatUint()](https://pkg.go.dev/strconv#FormatUint) from the stdlib.
+
 ## License
 
 Under [MIT](LICENSE)
diff --git a/base36.go b/base36.go
index 2158458..8e4f3dc 100644
--- a/base36.go
+++ b/base36.go
@@ -1,7 +1,6 @@
 package base36
 
 import (
-	"math"
 	"math/big"
 	"strings"
 )
@@ -13,21 +12,57 @@ var (
 		'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
 		'U', 'V', 'W', 'X', 'Y', 'Z'}
 
-	index = map[byte]int{
-		'0': 0, '1': 1, '2': 2, '3': 3, '4': 4,
-		'5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
-		'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14,
-		'F': 15, 'G': 16, 'H': 17, 'I': 18, 'J': 19,
-		'K': 20, 'L': 21, 'M': 22, 'N': 23, 'O': 24,
-		'P': 25, 'Q': 26, 'R': 27, 'S': 28, 'T': 29,
-		'U': 30, 'V': 31, 'W': 32, 'X': 33, 'Y': 34,
-		'Z': 35,
-		'a': 10, 'b': 11, 'c': 12, 'd': 13, 'e': 14,
-		'f': 15, 'g': 16, 'h': 17, 'i': 18, 'j': 19,
-		'k': 20, 'l': 21, 'm': 22, 'n': 23, 'o': 24,
-		'p': 25, 'q': 26, 'r': 27, 's': 28, 't': 29,
-		'u': 30, 'v': 31, 'w': 32, 'x': 33, 'y': 34,
-		'z': 35,
+	//index = map[byte]int{
+	//	'0': 0, '1': 1, '2': 2, '3': 3, '4': 4,
+	//	'5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
+	//	'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14,
+	//	'F': 15, 'G': 16, 'H': 17, 'I': 18, 'J': 19,
+	//	'K': 20, 'L': 21, 'M': 22, 'N': 23, 'O': 24,
+	//	'P': 25, 'Q': 26, 'R': 27, 'S': 28, 'T': 29,
+	//	'U': 30, 'V': 31, 'W': 32, 'X': 33, 'Y': 34,
+	//	'Z': 35,
+	//	'a': 10, 'b': 11, 'c': 12, 'd': 13, 'e': 14,
+	//	'f': 15, 'g': 16, 'h': 17, 'i': 18, 'j': 19,
+	//	'k': 20, 'l': 21, 'm': 22, 'n': 23, 'o': 24,
+	//	'p': 25, 'q': 26, 'r': 27, 's': 28, 't': 29,
+	//	'u': 30, 'v': 31, 'w': 32, 'x': 33, 'y': 34,
+	//	'z': 35,
+	//}
+	uint8Index = []uint64{
+		0,
+		0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+		0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+		0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+		0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+		0, 0, 0, 0, 0, 0, 0, 0, 1, 2,
+		3, 4, 5, 6, 7, 8, 9, 0, 0, 0,
+		0, 0, 0, 0, 10, 11, 12, 13, 14,
+		15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
+		25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
+		35, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13,
+		14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
+		24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
+		34, 35, 0, 0, 0, 0, 0, 0, 0, 0,
+		0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+		0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+		0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+		0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+		0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+		0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+		0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+		0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+		0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+		0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+		0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+		0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+		0, 0, 0, 0, 0, // 256
+	}
+	pow36Index = []uint64{
+		1, 36, 1296, 46656, 1679616, 60466176,
+		2176782336, 78364164096, 2821109907456,
+		101559956668416, 3656158440062976,
+		131621703842267136, 4738381338321616896,
+		9223372036854775808,
 	}
 )
 
@@ -35,20 +70,27 @@ var (
 func Encode(value uint64) string {
 	var res [16]byte
 	var i int
-	for i = len(res) - 1; value != 0; i-- {
+	for i = len(res) - 1; ; i-- {
 		res[i] = base36[value%36]
 		value /= 36
+		if value == 0 {
+			break
+		}
 	}
-	return string(res[i+1:])
+
+	return string(res[i:])
 }
 
 // Decode decodes a base36-encoded string.
 func Decode(s string) uint64 {
+	if len(s) > 13 {
+		s = s[:12]
+	}
 	res := uint64(0)
 	l := len(s) - 1
-	for idx := range s {
+	for idx := 0; idx < len(s); idx++ {
 		c := s[l-idx]
-		res += uint64(index[c]) * uint64(math.Pow(36, float64(idx)))
+		res += uint8Index[c] * pow36Index[idx]
 	}
 	return res
 }
diff --git a/base36_test.go b/base36_test.go
index 6a6b2a4..5f1e13e 100644
--- a/base36_test.go
+++ b/base36_test.go
@@ -12,7 +12,7 @@ var raw = []uint64{0, 50, 100, 999, 1000, 1111, 5959, 99999,
 	123456789, 5481594952936519619, math.MaxInt64 / 2048, math.MaxInt64 / 512,
 	math.MaxInt64, math.MaxUint64}
 
-var encoded = []string{"", "1E", "2S", "RR", "RS", "UV", "4LJ", "255R",
+var encoded = []string{"0", "1E", "2S", "RR", "RS", "UV", "4LJ", "255R",
 	"21I3V9", "15N9Z8L3AU4EB", "18CE53UN18F", "4XDKKFEK4XR",
 	"1Y2P0IJ32E8E7", "3W5E11264SGSF"}
 
diff --git a/debian/changelog b/debian/changelog
index f08d086..0bc8aaa 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+golang-github-martinlindhe-base36 (1.1.1+git20221101.1.9c25352-1) UNRELEASED; urgency=low
+
+  * New upstream snapshot.
+
+ -- Debian Janitor <janitor@jelmer.uk>  Mon, 21 Nov 2022 02:39:18 -0000
+
 golang-github-martinlindhe-base36 (1.0.0-3) unstable; urgency=medium
 
   [ Debian Janitor ]
diff --git a/example_test.go b/example_test.go
index 12250e9..f4596ab 100644
--- a/example_test.go
+++ b/example_test.go
@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/martinlindhe/base36"
+
 )
 
 func ExampleEncode() {
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..4f3cc8b
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,11 @@
+module github.com/martinlindhe/base36
+
+go 1.16
+
+require github.com/stretchr/testify v1.7.0
+
+require (
+	github.com/davecgh/go-spew v1.1.0 // indirect
+	github.com/pmezard/go-difflib v1.0.0 // indirect
+	gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
+)
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..acb88a4
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,11 @@
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
+github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

Debdiff

[The following lists of changes regard files as different if they have different names, permissions or owners.]

Files in second set of .debs but not in first

-rw-r--r--  root/root   /usr/share/gocode/src/github.com/martinlindhe/base36/go.mod
-rw-r--r--  root/root   /usr/share/gocode/src/github.com/martinlindhe/base36/go.sum

No differences were encountered in the control files

More details

Full run details