Skip to content

Commit

Permalink
use range over integer (new in go 1.22)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Feb 7, 2024
1 parent 96d57e4 commit 1b562b2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions lib/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var (
func getBIP39WordMap() map[string]bool {
count := bip39.WordCount()
m := make(map[string]bool, count)
for i := 0; i < count; i++ {
for i := range count {
word, ok := bip39.GetWord(i)
if !ok {
panic("NOT OK")
Expand Down Expand Up @@ -513,7 +513,7 @@ func TestGenerate(t *testing.T) {
PassLen: [2]int{14, 14},
Entropy: [2]float64{59.6, 59.7},
Validate: func(p string) bool {
for i := 0; i < 2; i++ {
for i := range 2 {
k := 7 * i
for _, c := range p[k : k+5] {
if c < 'a' || c > 'z' {
Expand Down Expand Up @@ -568,7 +568,7 @@ func TestGenerate(t *testing.T) {
PassLen: [2]int{16, 16},
Entropy: [2]float64{59.6, 59.7},
Validate: func(p string) bool {
for i := 0; i < 2; i++ {
for i := range 2 {
k := 8 * i
for _, c := range p[k : k+5] {
if c < 'a' || c > 'z' {
Expand Down Expand Up @@ -654,7 +654,7 @@ func TestGenerate(t *testing.T) {
PassLen: [2]int{8, 8},
Entropy: [2]float64{16, 16},
Validate: func(p string) bool {
for i := 0; i < len(p); i += 1 {
for i := range len(p) {
switch p[i : i+1] {
case "a", "b", "c", "d", "e", "f":
default:
Expand All @@ -669,7 +669,7 @@ func TestGenerate(t *testing.T) {
PassLen: [2]int{1, 1},
Entropy: [2]float64{3, 3},
Validate: func(p string) bool {
for i := 0; i < len(p); i += 1 {
for i := range len(p) {
switch p[i : i+1] {
case "a", "b", "c", "d", "e", "f", "g", "h", "i", "j":
default:
Expand All @@ -684,7 +684,7 @@ func TestGenerate(t *testing.T) {
PassLen: [2]int{8, 8},
Entropy: [2]float64{24, 24},
Validate: func(p string) bool {
for i := 0; i < len(p); i += 1 {
for i := range len(p) {
switch p[i : i+1] {
case "a", "b", "c", "d", "e", "f", "g", "h", "i", "j":
default:
Expand Down
4 changes: 2 additions & 2 deletions lib/justify.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func rjust(in []rune, width int, fillChar rune) []rune {
}
out := make([]rune, width)
fcc := width - len(in)
for i := 0; i < fcc; i++ {
for i := range fcc {
out[i] = fillChar
}
copy(out[fcc:], in)
Expand All @@ -36,7 +36,7 @@ func center(in []rune, width int, fillChar rune) []rune {
}
out := make([]rune, width)
fcc := int((width - len(in)) / 2)
for i := 0; i < fcc; i++ {
for i := range fcc {
out[i] = fillChar
}
copy(out[fcc:], in)
Expand Down
4 changes: 2 additions & 2 deletions lib/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ func (t *Trie) convert(origin string) (result string) {
originRune := []rune(origin)
result = ""

for l := 0; l < len(originRune); l++ {
for l := range len(originRune) {
t = root
foundVal := ""
depth := 0
for i := 0; i+l < len(originRune); i++ {
for i := range len(originRune) - l {
letter := string(originRune[l+i])
if t.children[letter] == nil {
// not found
Expand Down
4 changes: 2 additions & 2 deletions lib/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Benchmark_removeDuplicateRunes(b *testing.B) {
listLength := 100
count := b.N * 10000
lists := make([][]rune, count)
for i := 0; i < count; i++ {
for i := range count {
list := make([]rune, listLength)
for j := 0; j < listLength; j++ {
list[j] = rune(math_rand.Int32N(256))
Expand All @@ -61,7 +61,7 @@ func Benchmark_excludeCharsASCII(b *testing.B) {
listLength := 100
count := b.N * 10000
lists := make([][]rune, count)
for i := 0; i < count; i++ {
for i := range count {
list := make([]rune, listLength)
for j := 0; j < listLength; j++ {
list[j] = rune(math_rand.Int32N(256))
Expand Down

0 comments on commit 1b562b2

Please sign in to comment.