Skip to content

Commit

Permalink
Merge pull request #9 from lxzan/dev
Browse files Browse the repository at this point in the history
modify package name
  • Loading branch information
lxzan committed Dec 31, 2023
2 parents 274c760 + fc155ce commit 27d4f4c
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 55 deletions.
2 changes: 1 addition & 1 deletion algorithm/algorithm.go → algo/algorithm.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package algorithm
package algo

import (
"github.com/lxzan/dao/types/cmp"
Expand Down
2 changes: 1 addition & 1 deletion algorithm/algorithm_test.go → algo/algorithm_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package algorithm
package algo

import (
"github.com/lxzan/dao/hashmap"
Expand Down
2 changes: 1 addition & 1 deletion algorithm/sort.go → algo/sort.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package algorithm
package algo

import (
"github.com/lxzan/dao/types/cmp"
Expand Down
2 changes: 1 addition & 1 deletion algorithm/sort_test.go → algo/sort_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package algorithm
package algo

import (
"github.com/lxzan/dao/internal/utils"
Expand Down
6 changes: 3 additions & 3 deletions benchmark/rbtree_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package benchmark

import (
"github.com/lxzan/dao/algorithm"
"github.com/lxzan/dao/algo"
"github.com/lxzan/dao/rbtree"
"math/rand"
"testing"
Expand Down Expand Up @@ -41,7 +41,7 @@ func BenchmarkRBTree_FindAll(b *testing.B) {
for j := 0; j < bench_count; j++ {
x, y := rand.Intn(bench_count), rand.Intn(bench_count)
if x > y {
algorithm.Swap(&x, &y)
algo.Swap(&x, &y)
}
tree.
NewQuery().
Expand All @@ -65,7 +65,7 @@ func BenchmarkRBTree_FindAOne(b *testing.B) {
for j := 0; j < bench_count; j++ {
x, y := rand.Intn(bench_count), rand.Intn(bench_count)
if x > y {
algorithm.Swap(&x, &y)
algo.Swap(&x, &y)
}
tree.
NewQuery().
Expand Down
4 changes: 2 additions & 2 deletions benchmark/sort_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package benchmark

import (
"github.com/lxzan/dao/algorithm"
"github.com/lxzan/dao/algo"
"sort"
"testing"
)
Expand All @@ -10,7 +10,7 @@ func BenchmarkSort_Quick(b *testing.B) {
for i := 0; i < b.N; i++ {
var arr = make([]int, bench_count)
copy(arr, testvals[:bench_count])
algorithm.Sort(arr)
algo.Sort(arr)
}
}

Expand Down
6 changes: 3 additions & 3 deletions dict/dict_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dict

import (
"fmt"
"github.com/lxzan/dao/algorithm"
"github.com/lxzan/dao/algo"
"github.com/lxzan/dao/internal/utils"
"github.com/lxzan/dao/internal/validator"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -40,8 +40,8 @@ func TestNew(t *testing.T) {
return true
})

arr1 = algorithm.Unique(arr1)
arr2 = algorithm.Unique(arr2)
arr1 = algo.Unique(arr1)
arr2 = algo.Unique(arr2)
if !utils.IsSameSlice(arr1, arr2) {
t.Fatal("error!")
}
Expand Down
4 changes: 2 additions & 2 deletions dict/encode.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dict

import "github.com/lxzan/dao/algorithm"
import "github.com/lxzan/dao/algo"

var defaultIndexes = []uint8{32, 32, 16, 16, 16, 16, 16, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4}

Expand All @@ -24,7 +24,7 @@ func (c *Dict[T]) getIndex(iter *iterator) int {
}

func (c *Dict[T]) begin(key string, initialize bool) *iterator {
var iter = &iterator{Node: c.root, Key: key, N: algorithm.Min(len(key), len(c.indexes)-1), Initialize: initialize}
var iter = &iterator{Node: c.root, Key: key, N: algo.Min(len(key), len(c.indexes)-1), Initialize: initialize}
var idx = c.getIndex(iter)
if iter.Node.Children[idx] == nil {
if !iter.Initialize {
Expand Down
6 changes: 3 additions & 3 deletions heap/heap.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package heap

import (
"github.com/lxzan/dao/algorithm"
"github.com/lxzan/dao/algo"
"github.com/lxzan/dao/internal/utils"
"github.com/lxzan/dao/types/cmp"
)
Expand Down Expand Up @@ -42,7 +42,7 @@ func (c *Heap[T]) SetCap(n int) *Heap[T] {

// setWays 设置分叉数
func (c *Heap[T]) setWays(n uint32) *Heap[T] {
n = algorithm.SelectValue(n == 0, Quadratic, n)
n = algo.SelectValue(n == 0, Quadratic, n)
if !utils.IsBinaryNumber(n) {
panic("incorrect number of ways")
}
Expand Down Expand Up @@ -85,7 +85,7 @@ func (c *Heap[T]) down(i int) {
return
}

var end = algorithm.Min(base+c.ways, n-1)
var end = algo.Min(base+c.ways, n-1)
for j := base + 2; j <= end; j++ {
if c.less(j, index) {
index = j
Expand Down
6 changes: 3 additions & 3 deletions heap/heap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package heap

import (
"fmt"
"github.com/lxzan/dao/algorithm"
"github.com/lxzan/dao/algo"
"github.com/lxzan/dao/internal/utils"
"github.com/lxzan/dao/types/cmp"
"github.com/stretchr/testify/assert"
Expand All @@ -25,7 +25,7 @@ func validateHeap[T cmp.Ordered](t *testing.T, h *Heap[T], compare cmp.CompareFu
i++

var base = index << h.bits
var end = algorithm.Min(base+h.ways, n-1)
var end = algo.Min(base+h.ways, n-1)
for j := base + 1; j <= end; j++ {
child := h.data[j]
assert.True(t, compare(value, child) <= 0)
Expand All @@ -37,7 +37,7 @@ func validateHeap[T cmp.Ordered](t *testing.T, h *Heap[T], compare cmp.CompareFu
for h.Len() > 0 {
keys = append(keys, h.Pop())
}
assert.True(t, algorithm.IsSorted(keys, compare))
assert.True(t, algo.IsSorted(keys, compare))
}

func TestHeap_Random(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions heap/index.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package heap

import (
"github.com/lxzan/dao/algorithm"
"github.com/lxzan/dao/algo"
"github.com/lxzan/dao/internal/utils"
"github.com/lxzan/dao/types/cmp"
)
Expand Down Expand Up @@ -51,7 +51,7 @@ func NewIndexedHeap[K cmp.Ordered, V any](ways uint32, lessFunc cmp.LessFunc[K])

// SetForkNumber 设置分叉数
func (c *IndexedHeap[K, V]) setWays(n uint32) *IndexedHeap[K, V] {
n = algorithm.SelectValue(n == 0, Quadratic, n)
n = algo.SelectValue(n == 0, Quadratic, n)
if !utils.IsBinaryNumber(n) {
panic("incorrect number of ways")
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func (c *IndexedHeap[K, V]) down(i int) {
return
}

var end = algorithm.Min(base+c.ways, n-1)
var end = algo.Min(base+c.ways, n-1)
for j := base + 2; j <= end; j++ {
if c.less(j, index) {
index = j
Expand Down
8 changes: 4 additions & 4 deletions heap/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package heap

import (
"fmt"
"github.com/lxzan/dao/algorithm"
"github.com/lxzan/dao/algo"
"github.com/lxzan/dao/internal/utils"
"github.com/lxzan/dao/types/cmp"
"github.com/stretchr/testify/assert"
Expand All @@ -23,7 +23,7 @@ func validateIndexedHeap[K cmp.Ordered, V any](t *testing.T, h *IndexedHeap[K, V
i++

var base = ele.Index() << h.bits
var end = algorithm.Min(base+h.ways, n-1)
var end = algo.Min(base+h.ways, n-1)
for j := base + 1; j <= end; j++ {
child := h.GetByIndex(j)
assert.True(t, compare(ele.Key(), child.Key()) <= 0)
Expand All @@ -35,7 +35,7 @@ func validateIndexedHeap[K cmp.Ordered, V any](t *testing.T, h *IndexedHeap[K, V
for h.Len() > 0 {
keys = append(keys, h.Pop().Key())
}
assert.True(t, algorithm.IsSorted(keys, compare))
assert.True(t, algo.IsSorted(keys, compare))
}

func TestIndexedHeap_Random(t *testing.T) {
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestIndexedHeap_Sort(t *testing.T) {
for h.Len() > 0 {
arr = append(arr, h.Pop().Key())
}
assert.True(t, algorithm.IsSorted(arr, func(a, b int) int {
assert.True(t, algo.IsSorted(arr, func(a, b int) int {
if a > b {
return 1
} else if a < b {
Expand Down
4 changes: 2 additions & 2 deletions rbtree/query.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package rbtree

import (
"github.com/lxzan/dao/algorithm"
"github.com/lxzan/dao/algo"
"github.com/lxzan/dao/stack"
"github.com/lxzan/dao/types/cmp"
)
Expand Down Expand Up @@ -201,7 +201,7 @@ func (c *QueryBuilder[K, V]) getMaxPair(filter func(key K) bool) (result *Pair[K

func (c *QueryBuilder[K, V]) getMinPair(filter func(key K) bool) (result *Pair[K, V], exist bool) {
var s = stack.Stack[*rbtree_node[K, V]]{}
filter = algorithm.SelectValue(filter == nil, TrueFunc[K], filter)
filter = algo.SelectValue(filter == nil, TrueFunc[K], filter)
s.Push(c.tree.root)
for s.Len() > 0 {
var node = s.Pop()
Expand Down
14 changes: 7 additions & 7 deletions rbtree/rbtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package rbtree

import (
"fmt"
"github.com/lxzan/dao/algorithm"
"github.com/lxzan/dao/algo"
"github.com/lxzan/dao/hashmap"
"github.com/lxzan/dao/internal/utils"
"github.com/lxzan/dao/internal/validator"
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestRBTree_Between(t *testing.T) {
Order(DESC).
Limit(limit).
FindAll()
var keys1 = algorithm.Map[Pair[string, int], string](values, func(i int, v Pair[string, int]) string {
var keys1 = algo.Map[Pair[string, int], string](values, func(i int, v Pair[string, int]) string {
return v.Key
})

Expand All @@ -177,7 +177,7 @@ func TestRBTree_Between(t *testing.T) {
}
}
sort.Strings(keys2)
algorithm.Reverse(keys2)
algo.Reverse(keys2)
if len(keys2) > limit {
keys2 = keys2[:limit]
}
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestRBTree_Between(t *testing.T) {
Limit(limit).
Offset(10).
FindAll()
var keys1 = algorithm.Map[Pair[string, int], string](values, func(i int, v Pair[string, int]) string {
var keys1 = algo.Map[Pair[string, int], string](values, func(i int, v Pair[string, int]) string {
return v.Key
})

Expand Down Expand Up @@ -262,7 +262,7 @@ func TestRBTree_Between(t *testing.T) {
Order(ASC).
Limit(10).
FindAll()
var keys1 = algorithm.Map(values1, func(i int, v Pair[int, uint8]) int { return v.Key })
var keys1 = algo.Map(values1, func(i int, v Pair[int, uint8]) int { return v.Key })
assert.True(t, utils.IsSameSlice(keys1, []int{1, 2, 3}))
})
}
Expand All @@ -285,7 +285,7 @@ func TestRBTree_GreaterEqual(t *testing.T) {
Left(func(key string) bool { return key >= left }).
Limit(limit).
FindAll()
var keys1 = algorithm.Map[Pair[string, int], string](values, func(i int, v Pair[string, int]) string {
var keys1 = algo.Map[Pair[string, int], string](values, func(i int, v Pair[string, int]) string {
return v.Key
})
var keys2 = make([]string, 0)
Expand Down Expand Up @@ -322,7 +322,7 @@ func TestRBTree_LessEqual(t *testing.T) {
Order(DESC).
Limit(limit).
FindAll()
var keys1 = algorithm.Map[Pair[string, int], string](results, func(i int, v Pair[string, int]) string {
var keys1 = algo.Map[Pair[string, int], string](results, func(i int, v Pair[string, int]) string {
return v.Key
})
var keys2 = make([]string, 0)
Expand Down
6 changes: 3 additions & 3 deletions segment_tree/impl.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package segment_tree

import (
"github.com/lxzan/dao/algorithm"
"github.com/lxzan/dao/algo"
)

type Int64 int64
Expand Down Expand Up @@ -33,8 +33,8 @@ type Int64Schema struct {
// Merge 合并摘要信息
func (c Int64Schema) Merge(d Int64Schema) Int64Schema {
return Int64Schema{
MaxValue: algorithm.Max(c.MaxValue, d.MaxValue),
MinValue: algorithm.Min(c.MinValue, d.MinValue),
MaxValue: algo.Max(c.MaxValue, d.MaxValue),
MinValue: algo.Min(c.MinValue, d.MinValue),
Sum: c.Sum + d.Sum,
}
}
10 changes: 5 additions & 5 deletions segment_tree/segement_tree_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package segment_tree

import (
"github.com/lxzan/dao/algorithm"
"github.com/lxzan/dao/algo"
"github.com/lxzan/dao/internal/utils"
"testing"
)
Expand Down Expand Up @@ -30,8 +30,8 @@ func TestSegmentTree_Query(t *testing.T) {
}
for j := left; j <= right; j++ {
result2.Sum += arr[j].Value()
result2.MaxValue = algorithm.Max(result2.MaxValue, arr[j].Value())
result2.MinValue = algorithm.Min(result2.MinValue, arr[j].Value())
result2.MaxValue = algo.Max(result2.MaxValue, arr[j].Value())
result2.MinValue = algo.Min(result2.MinValue, arr[j].Value())
}

if result1.Sum != result2.Sum || result1.MinValue != result2.MinValue || result1.MaxValue != result2.MaxValue {
Expand Down Expand Up @@ -60,8 +60,8 @@ func TestSegmentTree_Query(t *testing.T) {
}
for j := left; j <= right; j++ {
result2.Sum += arr[j].Value()
result2.MaxValue = algorithm.Max(result2.MaxValue, arr[j].Value())
result2.MinValue = algorithm.Min(result2.MinValue, arr[j].Value())
result2.MaxValue = algo.Max(result2.MaxValue, arr[j].Value())
result2.MinValue = algo.Min(result2.MinValue, arr[j].Value())
}

if result1.Sum != result2.Sum || result1.MinValue != result2.MinValue || result1.MaxValue != result2.MaxValue {
Expand Down
Loading

0 comments on commit 27d4f4c

Please sign in to comment.