diff --git a/algorithm/search.go b/algorithm/search.go index 5243e2c..da1202f 100644 --- a/algorithm/search.go +++ b/algorithm/search.go @@ -4,7 +4,7 @@ // Package algorithm contain some basic algorithm functions. eg. sort, search, list, linklist, stack, queue, tree, graph. package algorithm -import "github.com/duke-git/lancet/v2/lancetconstraints" +import "github.com/duke-git/lancet/v2/constraints" // Search algorithms see https://github.com/TheAlgorithms/Go/tree/master/search @@ -23,7 +23,7 @@ func LinearSearch[T any](slice []T, target T, equal func(a, b T) bool) int { // BinarySearch return the index of target within a sorted slice, use binary search (recursive call itself). // If not found return -1. // Play: https://go.dev/play/p/t6MeGiUSN47 -func BinarySearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int { +func BinarySearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator constraints.Comparator) int { if highIndex < lowIndex || len(sortedSlice) == 0 { return -1 } @@ -44,7 +44,7 @@ func BinarySearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, com // BinaryIterativeSearch return the index of target within a sorted slice, use binary search (no recursive). // If not found return -1. // Play: https://go.dev/play/p/Anozfr8ZLH3 -func BinaryIterativeSearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int { +func BinaryIterativeSearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator constraints.Comparator) int { startIndex := lowIndex endIndex := highIndex diff --git a/algorithm/sort.go b/algorithm/sort.go index aaf2f45..32da184 100644 --- a/algorithm/sort.go +++ b/algorithm/sort.go @@ -3,11 +3,11 @@ package algorithm -import "github.com/duke-git/lancet/v2/lancetconstraints" +import "github.com/duke-git/lancet/v2/constraints" // BubbleSort applys the bubble sort algorithm to sort the collection, will change the original collection data. // Play: https://go.dev/play/p/GNdv7Jg2Taj -func BubbleSort[T any](slice []T, comparator lancetconstraints.Comparator) { +func BubbleSort[T any](slice []T, comparator constraints.Comparator) { for i := 0; i < len(slice); i++ { for j := 0; j < len(slice)-1-i; j++ { isCurrGreatThanNext := comparator.Compare(slice[j], slice[j+1]) == 1 @@ -20,7 +20,7 @@ func BubbleSort[T any](slice []T, comparator lancetconstraints.Comparator) { // InsertionSort applys the insertion sort algorithm to sort the collection, will change the original collection data. // Play: https://go.dev/play/p/G5LJiWgJJW6 -func InsertionSort[T any](slice []T, comparator lancetconstraints.Comparator) { +func InsertionSort[T any](slice []T, comparator constraints.Comparator) { for i := 0; i < len(slice); i++ { for j := i; j > 0; j-- { isPreLessThanCurrent := comparator.Compare(slice[j], slice[j-1]) == -1 @@ -35,7 +35,7 @@ func InsertionSort[T any](slice []T, comparator lancetconstraints.Comparator) { // SelectionSort applys the selection sort algorithm to sort the collection, will change the original collection data. // Play: https://go.dev/play/p/oXovbkekayS -func SelectionSort[T any](slice []T, comparator lancetconstraints.Comparator) { +func SelectionSort[T any](slice []T, comparator constraints.Comparator) { for i := 0; i < len(slice); i++ { min := i for j := i + 1; j < len(slice); j++ { @@ -49,7 +49,7 @@ func SelectionSort[T any](slice []T, comparator lancetconstraints.Comparator) { // ShellSort applys the shell sort algorithm to sort the collection, will change the original collection data. // Play: https://go.dev/play/p/3ibkszpJEu3 -func ShellSort[T any](slice []T, comparator lancetconstraints.Comparator) { +func ShellSort[T any](slice []T, comparator constraints.Comparator) { size := len(slice) gap := 1 @@ -69,11 +69,11 @@ func ShellSort[T any](slice []T, comparator lancetconstraints.Comparator) { // QuickSort quick sorting for slice, lowIndex is 0 and highIndex is len(slice)-1. // Play: https://go.dev/play/p/7Y7c1Elk3ax -func QuickSort[T any](slice []T, comparator lancetconstraints.Comparator) { +func QuickSort[T any](slice []T, comparator constraints.Comparator) { quickSort(slice, 0, len(slice)-1, comparator) } -func quickSort[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) { +func quickSort[T any](slice []T, lowIndex, highIndex int, comparator constraints.Comparator) { if lowIndex < highIndex { p := partition(slice, lowIndex, highIndex, comparator) quickSort(slice, lowIndex, p-1, comparator) @@ -82,7 +82,7 @@ func quickSort[T any](slice []T, lowIndex, highIndex int, comparator lancetconst } // partition split slice into two parts -func partition[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int { +func partition[T any](slice []T, lowIndex, highIndex int, comparator constraints.Comparator) int { p := slice[highIndex] i := lowIndex for j := lowIndex; j < highIndex; j++ { @@ -99,7 +99,7 @@ func partition[T any](slice []T, lowIndex, highIndex int, comparator lancetconst // HeapSort applys the heap sort algorithm to sort the collection, will change the original collection data. // Play: https://go.dev/play/p/u6Iwa1VZS_f -func HeapSort[T any](slice []T, comparator lancetconstraints.Comparator) { +func HeapSort[T any](slice []T, comparator constraints.Comparator) { size := len(slice) for i := size/2 - 1; i >= 0; i-- { @@ -111,7 +111,7 @@ func HeapSort[T any](slice []T, comparator lancetconstraints.Comparator) { } } -func sift[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) { +func sift[T any](slice []T, lowIndex, highIndex int, comparator constraints.Comparator) { i := lowIndex j := 2*i + 1 @@ -133,11 +133,11 @@ func sift[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraint // MergeSort applys the merge sort algorithm to sort the collection, will change the original collection data. // Play: https://go.dev/play/p/ydinn9YzUJn -func MergeSort[T any](slice []T, comparator lancetconstraints.Comparator) { +func MergeSort[T any](slice []T, comparator constraints.Comparator) { mergeSort(slice, 0, len(slice)-1, comparator) } -func mergeSort[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) { +func mergeSort[T any](slice []T, lowIndex, highIndex int, comparator constraints.Comparator) { if lowIndex < highIndex { mid := (lowIndex + highIndex) / 2 mergeSort(slice, lowIndex, mid, comparator) @@ -146,7 +146,7 @@ func mergeSort[T any](slice []T, lowIndex, highIndex int, comparator lancetconst } } -func merge[T any](slice []T, lowIndex, midIndex, highIndex int, comparator lancetconstraints.Comparator) { +func merge[T any](slice []T, lowIndex, midIndex, highIndex int, comparator constraints.Comparator) { i := lowIndex j := midIndex + 1 temp := []T{} @@ -175,7 +175,7 @@ func merge[T any](slice []T, lowIndex, midIndex, highIndex int, comparator lance // CountSort applys the count sort algorithm to sort the collection, don't change the original collection data. // Play: https://go.dev/play/p/tB-Umgm0DrP -func CountSort[T any](slice []T, comparator lancetconstraints.Comparator) []T { +func CountSort[T any](slice []T, comparator constraints.Comparator) []T { size := len(slice) out := make([]T, size) diff --git a/algorithm/sort_test.go b/algorithm/sort_test.go index 5270fbb..d514aa3 100644 --- a/algorithm/sort_test.go +++ b/algorithm/sort_test.go @@ -16,7 +16,7 @@ type people struct { // PeopleAageComparator sort people slice by age field type peopleAgeComparator struct{} -// Compare implements github.com/duke-git/lancet/v2/lancetconstraints/constraints.go/Comparator +// Compare implements github.com/duke-git/lancet/v2/constraints/constraints.go/Comparator func (pc *peopleAgeComparator) Compare(v1 any, v2 any) int { p1, _ := v1.(people) p2, _ := v2.(people) diff --git a/lancetconstraints/constraints.go b/constraints/constraints.go similarity index 81% rename from lancetconstraints/constraints.go rename to constraints/constraints.go index b663ba6..fc8aa4a 100644 --- a/lancetconstraints/constraints.go +++ b/constraints/constraints.go @@ -1,8 +1,8 @@ // Copyright 2021 dudaodong@gmail.com. All rights reserved. // Use of this source code is governed by MIT license -// Package lancetconstraints contain some comstomer constraints. -package lancetconstraints +// Package constraints contain some custom interface. +package constraints // Comparator is for comparing two values type Comparator interface { diff --git a/datastructure/heap/maxheap.go b/datastructure/heap/maxheap.go index e496e14..e913c68 100644 --- a/datastructure/heap/maxheap.go +++ b/datastructure/heap/maxheap.go @@ -7,18 +7,18 @@ package datastructure import ( "fmt" - "github.com/duke-git/lancet/v2/lancetconstraints" + "github.com/duke-git/lancet/v2/constraints" ) // MaxHeap implements a binary max heap -// type T should implements Compare function in lancetconstraints.Comparator interface. +// type T should implements Compare function in constraints.Comparator interface. type MaxHeap[T any] struct { data []T - comparator lancetconstraints.Comparator + comparator constraints.Comparator } // NewMaxHeap returns a MaxHeap instance with the given comparator. -func NewMaxHeap[T any](comparator lancetconstraints.Comparator) *MaxHeap[T] { +func NewMaxHeap[T any](comparator constraints.Comparator) *MaxHeap[T] { return &MaxHeap[T]{ data: make([]T, 0), comparator: comparator, @@ -26,7 +26,7 @@ func NewMaxHeap[T any](comparator lancetconstraints.Comparator) *MaxHeap[T] { } // BuildMaxHeap builds a MaxHeap instance with data and given comparator. -func BuildMaxHeap[T any](data []T, comparator lancetconstraints.Comparator) *MaxHeap[T] { +func BuildMaxHeap[T any](data []T, comparator constraints.Comparator) *MaxHeap[T] { heap := &MaxHeap[T]{ data: make([]T, 0, len(data)), comparator: comparator, diff --git a/datastructure/queue/priorityqueue.go b/datastructure/queue/priorityqueue.go index 741ec9a..76a558f 100644 --- a/datastructure/queue/priorityqueue.go +++ b/datastructure/queue/priorityqueue.go @@ -8,20 +8,20 @@ package datastructure import ( "errors" - "github.com/duke-git/lancet/v2/lancetconstraints" + "github.com/duke-git/lancet/v2/constraints" ) // PriorityQueue is a priority queue implemented by binary heap tree -// type T should implements Compare function in lancetconstraints.Comparator interface. +// type T should implements Compare function in constraints.Comparator interface. type PriorityQueue[T any] struct { items []T size int - comparator lancetconstraints.Comparator + comparator constraints.Comparator } // NewPriorityQueue return a pointer of PriorityQueue // param `comparator` is used to compare values in the queue -func NewPriorityQueue[T any](capacity int, comparator lancetconstraints.Comparator) *PriorityQueue[T] { +func NewPriorityQueue[T any](capacity int, comparator constraints.Comparator) *PriorityQueue[T] { return &PriorityQueue[T]{ items: make([]T, capacity+1), size: 0, diff --git a/datastructure/tree/bstree.go b/datastructure/tree/bstree.go index db9618b..fd63011 100644 --- a/datastructure/tree/bstree.go +++ b/datastructure/tree/bstree.go @@ -7,22 +7,22 @@ package datastructure import ( "math" + "github.com/duke-git/lancet/v2/constraints" "github.com/duke-git/lancet/v2/datastructure" - "github.com/duke-git/lancet/v2/lancetconstraints" ) // BSTree is a binary search tree data structure in which each node has at most two children, // which are referred to as the left child and the right child. // In BSTree: leftNode < rootNode < rightNode -// type T should implements Compare function in lancetconstraints.Comparator interface. +// type T should implements Compare function in constraints.Comparator interface. type BSTree[T any] struct { root *datastructure.TreeNode[T] - comparator lancetconstraints.Comparator + comparator constraints.Comparator } // NewBSTree create a BSTree pointer // param `comparator` is used to compare values in the tree -func NewBSTree[T any](rootData T, comparator lancetconstraints.Comparator) *BSTree[T] { +func NewBSTree[T any](rootData T, comparator constraints.Comparator) *BSTree[T] { root := datastructure.NewTreeNode(rootData) return &BSTree[T]{root, comparator} } @@ -87,7 +87,7 @@ func (t *BSTree[T]) HasSubTree(subTree *BSTree[T]) bool { } func hasSubTree[T any](superTreeRoot, subTreeRoot *datastructure.TreeNode[T], - comparator lancetconstraints.Comparator) bool { + comparator constraints.Comparator) bool { result := false if superTreeRoot != nil && subTreeRoot != nil { diff --git a/datastructure/tree/tree_internal.go b/datastructure/tree/tree_internal.go index 940fe25..5151a0d 100644 --- a/datastructure/tree/tree_internal.go +++ b/datastructure/tree/tree_internal.go @@ -4,8 +4,8 @@ import ( "fmt" "math" + "github.com/duke-git/lancet/v2/constraints" "github.com/duke-git/lancet/v2/datastructure" - "github.com/duke-git/lancet/v2/lancetconstraints" ) func preOrderTraverse[T any](node *datastructure.TreeNode[T]) []T { @@ -86,7 +86,7 @@ func levelOrderTraverse[T any](root *datastructure.TreeNode[T], traversal *[]T) } } -func insertTreeNode[T any](rootNode, newNode *datastructure.TreeNode[T], comparator lancetconstraints.Comparator) { +func insertTreeNode[T any](rootNode, newNode *datastructure.TreeNode[T], comparator constraints.Comparator) { if comparator.Compare(newNode.Value, rootNode.Value) == -1 { if rootNode.Left == nil { rootNode.Left = newNode @@ -103,7 +103,7 @@ func insertTreeNode[T any](rootNode, newNode *datastructure.TreeNode[T], compara } // todo, delete root node failed -func deleteTreeNode[T any](node *datastructure.TreeNode[T], data T, comparator lancetconstraints.Comparator) *datastructure.TreeNode[T] { +func deleteTreeNode[T any](node *datastructure.TreeNode[T], data T, comparator constraints.Comparator) *datastructure.TreeNode[T] { if node == nil { return nil } @@ -216,7 +216,7 @@ func calculateDepth[T any](node *datastructure.TreeNode[T], depth int) int { return max(calculateDepth(node.Left, depth+1), calculateDepth(node.Right, depth+1)) } -func isSubTree[T any](superTreeRoot, subTreeRoot *datastructure.TreeNode[T], comparator lancetconstraints.Comparator) bool { +func isSubTree[T any](superTreeRoot, subTreeRoot *datastructure.TreeNode[T], comparator constraints.Comparator) bool { if subTreeRoot == nil { return true } diff --git a/docs/api/packages/algorithm.md b/docs/api/packages/algorithm.md index f5d5f1b..865ecba 100644 --- a/docs/api/packages/algorithm.md +++ b/docs/api/packages/algorithm.md @@ -43,12 +43,12 @@ import ( ### BubbleSort -
冒泡排序,参数comparator需要实现包lancetconstraints.Comparator。
+冒泡排序,参数comparator需要实现包constraints.Comparator。
函数签名: ```go -func BubbleSort[T any](slice []T, comparator lancetconstraints.Comparator) +func BubbleSort[T any](slice []T, comparator constraints.Comparator) ``` 示例:[运行](https://go.dev/play/p/GNdv7Jg2Taj) @@ -91,12 +91,12 @@ func main() { ### InsertionSort -插入排序,参数comparator需要实现包lancetconstraints.Comparator。
+插入排序,参数comparator需要实现包constraints.Comparator。
函数签名: ```go -func InsertionSort[T any](slice []T, comparator lancetconstraints.Comparator) +func InsertionSort[T any](slice []T, comparator constraints.Comparator) ``` 示例:[运行](https://go.dev/play/p/G5LJiWgJJW6) @@ -117,7 +117,7 @@ type people struct { // PeopleAageComparator sort people slice by age field type peopleAgeComparator struct{} -// Compare implements github.com/duke-git/lancet/lancetconstraints/constraints.go/Comparator +// Compare implements github.com/duke-git/lancet/constraints/constraints.go/Comparator func (pc *peopleAgeComparator) Compare(v1 any, v2 any) int { p1, _ := v1.(people) p2, _ := v2.(people) @@ -154,12 +154,12 @@ func main() { ### SelectionSort -选择排序,参数comparator需要实现包lancetconstraints.Comparator。
+选择排序,参数comparator需要实现包constraints.Comparator。
函数签名: ```go -func SelectionSort[T any](slice []T, comparator lancetconstraints.Comparator) +func SelectionSort[T any](slice []T, comparator constraints.Comparator) ``` 示例:[运行](https://go.dev/play/p/oXovbkekayS) @@ -202,12 +202,12 @@ func main() { ### ShellSort -希尔排序,参数comparator需要实现包lancetconstraints.Comparator。
+希尔排序,参数comparator需要实现包constraints.Comparator。
函数签名: ```go -func ShellSort[T any](slice []T, comparator lancetconstraints.Comparator) +func ShellSort[T any](slice []T, comparator constraints.Comparator) ``` 示例:[运行](https://go.dev/play/p/3ibkszpJEu3) @@ -250,12 +250,12 @@ func main() { ### QuickSort -快速排序,参数comparator需要实现包lancetconstraints.Comparator。
+快速排序,参数comparator需要实现包constraints.Comparator。
函数签名: ```go -func QuickSort[T any](slice []T comparator lancetconstraints.Comparator) +func QuickSort[T any](slice []T comparator constraints.Comparator) ``` 示例:[运行](https://go.dev/play/p/7Y7c1Elk3ax) @@ -298,12 +298,12 @@ func main() { ### HeapSort -堆排序,参数comparator需要实现包lancetconstraints.Comparator。
+堆排序,参数comparator需要实现包constraints.Comparator。
函数签名: ```go -func HeapSort[T any](slice []T, comparator lancetconstraints.Comparator) +func HeapSort[T any](slice []T, comparator constraints.Comparator) ``` 示例:[运行](https://go.dev/play/p/u6Iwa1VZS_f) @@ -346,12 +346,12 @@ func main() { ### MergeSort -归并排序,参数comparator需要实现包lancetconstraints.Comparator。
+归并排序,参数comparator需要实现包constraints.Comparator。
函数签名: ```go -func MergeSort[T any](slice []T, comparator lancetconstraints.Comparator) +func MergeSort[T any](slice []T, comparator constraints.Comparator) ``` 示例:[运行](https://go.dev/play/p/ydinn9YzUJn) @@ -394,12 +394,12 @@ func main() { ### CountSort -计数排序,参数comparator需要实现包lancetconstraints.Comparator。
+计数排序,参数comparator需要实现包constraints.Comparator。
函数签名: ```go -func CountSort[T any](slice []T, comparator lancetconstraints.Comparator) []T +func CountSort[T any](slice []T, comparator constraints.Comparator) []T ``` 示例:[运行](https://go.dev/play/p/tB-Umgm0DrP) @@ -443,12 +443,12 @@ func main() { ### BinarySearch -二分递归查找,返回元素索引,未找到元素返回-1,参数comparator需要实现包lancetconstraints.Comparator。
+二分递归查找,返回元素索引,未找到元素返回-1,参数comparator需要实现包constraints.Comparator。
函数签名: ```go -func BinarySearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int +func BinarySearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator constraints.Comparator) int ``` 示例: [运行](https://go.dev/play/p/t6MeGiUSN47) @@ -494,12 +494,12 @@ func main() { ### BinaryIterativeSearch -二分迭代查找,返回元素索引,未找到元素返回-1,参数comparator需要实现包lancetconstraints.Comparator。
+二分迭代查找,返回元素索引,未找到元素返回-1,参数comparator需要实现包constraints.Comparator。
函数签名: ```go -func BinaryIterativeSearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int +func BinaryIterativeSearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator constraints.Comparator) int ``` 示例: [运行](https://go.dev/play/p/Anozfr8ZLH3) diff --git a/docs/api/packages/datastructure/heap.md b/docs/api/packages/datastructure/heap.md index e3bc498..e4c5961 100644 --- a/docs/api/packages/datastructure/heap.md +++ b/docs/api/packages/datastructure/heap.md @@ -44,9 +44,9 @@ MaxHeap是通过slice实现的二叉堆树,根节点的key既大于等于左 ```go type MaxHeap[T any] struct { data []T - comparator lancetconstraints.Comparator + comparator constraints.Comparator } -func NewMaxHeap[T any](comparator lancetconstraints.Comparator) *MaxHeap[T] +func NewMaxHeap[T any](comparator constraints.Comparator) *MaxHeap[T] ``` 示例: diff --git a/docs/api/packages/datastructure/queue.md b/docs/api/packages/datastructure/queue.md index 7cd688e..9eca042 100644 --- a/docs/api/packages/datastructure/queue.md +++ b/docs/api/packages/datastructure/queue.md @@ -1100,12 +1100,12 @@ func main() { 函数签名: ```go -func NewPriorityQueue[T any](capacity int, comparator lancetconstraints.Comparator) *PriorityQueue[T] +func NewPriorityQueue[T any](capacity int, comparator constraints.Comparator) *PriorityQueue[T] type PriorityQueue[T any] struct { items []T size int - comparator lancetconstraints.Comparator + comparator constraints.Comparator } ``` 示例: diff --git a/docs/api/packages/datastructure/tree.md b/docs/api/packages/datastructure/tree.md index 1bcda76..d01997f 100644 --- a/docs/api/packages/datastructure/tree.md +++ b/docs/api/packages/datastructure/tree.md @@ -41,7 +41,7 @@ import ( ## 文档 ## 1. BSTree -BSTree是一种二叉搜索树数据结构,其中每个节点有两个孩子,分别称为左孩子和右孩子。 在 BSTree 中:leftNode < rootNode < rightNode。 T类型应该实现lancetconstraints.Comparator。 +BSTree是一种二叉搜索树数据结构,其中每个节点有两个孩子,分别称为左孩子和右孩子。 在 BSTree 中:leftNode < rootNode < rightNode。 T类型应该实现constraints.Comparator。 ### NewBSTree返回BSTree指针实例
@@ -49,11 +49,11 @@ BSTree是一种二叉搜索树数据结构,其中每个节点有两个孩子 函数签名: ```go -func NewBSTree[T any](rootData T, comparator lancetconstraints.Comparator) *BSTree[T] +func NewBSTree[T any](rootData T, comparator constraints.Comparator) *BSTree[T] type BSTree[T any] struct { root *datastructure.TreeNode[T] - comparator lancetconstraints.Comparator + comparator constraints.Comparator } type TreeNode[T any] struct { diff --git a/docs/en/api/packages/algorithm.md b/docs/en/api/packages/algorithm.md index 6af30e3..c2d3045 100644 --- a/docs/en/api/packages/algorithm.md +++ b/docs/en/api/packages/algorithm.md @@ -43,12 +43,12 @@ import ( ### BubbleSort -Sort slice with bubble sort algorithm. Param comparator should implements lancetconstraints.Comparator.
+Sort slice with bubble sort algorithm. Param comparator should implements constraints.Comparator.
Signature: ```go -func BubbleSort[T any](slice []T, comparator lancetconstraints.Comparator) +func BubbleSort[T any](slice []T, comparator constraints.Comparator) ``` Example: [Run](https://go.dev/play/p/GNdv7Jg2Taj) @@ -91,12 +91,12 @@ func main() { ### InsertionSort -Sort slice with insertion sort algorithm. Param comparator should implements lancetconstraints.Comparator.
+Sort slice with insertion sort algorithm. Param comparator should implements constraints.Comparator.
Signature: ```go -func InsertionSort[T any](slice []T, comparator lancetconstraints.Comparator) +func InsertionSort[T any](slice []T, comparator constraints.Comparator) ``` Example: [Run](https://go.dev/play/p/G5LJiWgJJW6) @@ -117,7 +117,7 @@ type people struct { // PeopleAageComparator sort people slice by age field type peopleAgeComparator struct{} -// Compare implements github.com/duke-git/lancet/lancetconstraints/constraints.go/Comparator +// Compare implements github.com/duke-git/lancet/constraints/constraints.go/Comparator func (pc *peopleAgeComparator) Compare(v1 any, v2 any) int { p1, _ := v1.(people) p2, _ := v2.(people) @@ -154,12 +154,12 @@ func main() { ### SelectionSort -Sort slice with selection sort algorithm. Param comparator should implements lancetconstraints.Comparator.
+Sort slice with selection sort algorithm. Param comparator should implements constraints.Comparator.
Signature: ```go -func SelectionSort[T any](slice []T, comparator lancetconstraints.Comparator) +func SelectionSort[T any](slice []T, comparator constraints.Comparator) ``` Example: [Run](https://go.dev/play/p/oXovbkekayS) @@ -202,12 +202,12 @@ func main() { ### ShellSort -Sort slice with shell sort algorithm. Param comparator should implements lancetconstraints.Comparator.
+Sort slice with shell sort algorithm. Param comparator should implements constraints.Comparator.
Signature: ```go -func ShellSort[T any](slice []T, comparator lancetconstraints.Comparator) +func ShellSort[T any](slice []T, comparator constraints.Comparator) ``` Example: [Run](https://go.dev/play/p/3ibkszpJEu3) @@ -250,12 +250,12 @@ func main() { ### QuickSort -Sort slice with quick sort algorithm. Param comparator should implements lancetconstraints.Comparator.
+Sort slice with quick sort algorithm. Param comparator should implements constraints.Comparator.
Signature: ```go -func QuickSort[T any](slice []T comparator lancetconstraints.Comparator) +func QuickSort[T any](slice []T comparator constraints.Comparator) ``` Example:[Run](https://go.dev/play/p/7Y7c1Elk3ax) @@ -298,12 +298,12 @@ func main() { ### HeapSort -Sort slice with heap sort algorithm. Param comparator should implements lancetconstraints.Comparator.
+Sort slice with heap sort algorithm. Param comparator should implements constraints.Comparator.
Signature: ```go -func HeapSort[T any](slice []T, comparator lancetconstraints.Comparator) +func HeapSort[T any](slice []T, comparator constraints.Comparator) ``` Example: [Run](https://go.dev/play/p/u6Iwa1VZS_f) @@ -346,12 +346,12 @@ func main() { ### MergeSort -Sort slice with merge sort algorithm. Param comparator should implements lancetconstraints.Comparator.
+Sort slice with merge sort algorithm. Param comparator should implements constraints.Comparator.
Signature: ```go -func MergeSort[T any](slice []T, comparator lancetconstraints.Comparator) +func MergeSort[T any](slice []T, comparator constraints.Comparator) ``` Example: [Run](https://go.dev/play/p/ydinn9YzUJn) @@ -394,12 +394,12 @@ func main() { ### CountSort -Sort slice with count sort algorithm. Param comparator should implements lancetconstraints.Comparator.
+Sort slice with count sort algorithm. Param comparator should implements constraints.Comparator.
Signature: ```go -func CountSort[T any](slice []T, comparator lancetconstraints.Comparator) []T +func CountSort[T any](slice []T, comparator constraints.Comparator) []T ``` Example: [Run](https://go.dev/play/p/tB-Umgm0DrP) @@ -448,7 +448,7 @@ func main() { Signature: ```go -func BinarySearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int +func BinarySearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator constraints.Comparator) int ``` Example: [Run](https://go.dev/play/p/t6MeGiUSN47) @@ -499,7 +499,7 @@ func main() { Signature: ```go -func BinaryIterativeSearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int +func BinaryIterativeSearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator constraints.Comparator) int ``` Example: [Run](https://go.dev/play/p/Anozfr8ZLH3) diff --git a/docs/en/api/packages/datastructure/heap.md b/docs/en/api/packages/datastructure/heap.md index 01c0c4f..863bfc3 100644 --- a/docs/en/api/packages/datastructure/heap.md +++ b/docs/en/api/packages/datastructure/heap.md @@ -44,9 +44,9 @@ MaxHeap is a binary heap tree implemented by slice, The key of the root node is ```go type MaxHeap[T any] struct { data []T - comparator lancetconstraints.Comparator + comparator constraints.Comparator } -func NewMaxHeap[T any](comparator lancetconstraints.Comparator) *MaxHeap[T] +func NewMaxHeap[T any](comparator constraints.Comparator) *MaxHeap[T] ``` Example: diff --git a/docs/en/api/packages/datastructure/queue.md b/docs/en/api/packages/datastructure/queue.md index f8d6b78..623adc4 100644 --- a/docs/en/api/packages/datastructure/queue.md +++ b/docs/en/api/packages/datastructure/queue.md @@ -1100,12 +1100,12 @@ Common queue implemented by slice. Signature: ```go -func NewPriorityQueue[T any](capacity int, comparator lancetconstraints.Comparator) *PriorityQueue[T] +func NewPriorityQueue[T any](capacity int, comparator constraints.Comparator) *PriorityQueue[T] type PriorityQueue[T any] struct { items []T size int - comparator lancetconstraints.Comparator + comparator constraints.Comparator } ``` Example: diff --git a/docs/en/api/packages/datastructure/tree.md b/docs/en/api/packages/datastructure/tree.md index 1365de8..38d57ae 100644 --- a/docs/en/api/packages/datastructure/tree.md +++ b/docs/en/api/packages/datastructure/tree.md @@ -41,7 +41,7 @@ import ( ## Documentation ## 1. BSTree -BSTree is a binary search tree data structure in which each node has at two children, which are referred to as the left child and the right child. In BSTree: leftNode < rootNode < rightNode. Type T should implements Compare function in lancetconstraints.Comparator interface. +BSTree is a binary search tree data structure in which each node has at two children, which are referred to as the left child and the right child. In BSTree: leftNode < rootNode < rightNode. Type T should implements Compare function in constraints.Comparator interface. ### NewBSTreeMake a BSTree pointer instance
@@ -49,11 +49,11 @@ BSTree is a binary search tree data structure in which each node has at two chil Signature: ```go -func NewBSTree[T any](rootData T, comparator lancetconstraints.Comparator) *BSTree[T] +func NewBSTree[T any](rootData T, comparator constraints.Comparator) *BSTree[T] type BSTree[T any] struct { root *datastructure.TreeNode[T] - comparator lancetconstraints.Comparator + comparator constraints.Comparator } type TreeNode[T any] struct {