generated from goexl/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f86781
commit 3020e4e
Showing
14 changed files
with
126 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ import ( | |
"github.com/goexl/collection/internal/kernel" | ||
) | ||
|
||
// Collection 集合 | ||
type Collection = kernel.Collection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
module github.com/goexl/collection | ||
|
||
go 1.23 | ||
|
||
require github.com/stretchr/testify v1.10.0 | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package kernel | ||
|
||
// Collection 集合 | ||
type Collection interface { | ||
// Size 大小 | ||
Size() int | ||
|
||
// Empty 是否为空 | ||
Empty() bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
package kernel | ||
|
||
// Queue 队列 | ||
type Queue[T any] interface { | ||
Collection | ||
|
||
// Enqueue 入队 | ||
Enqueue(T, ...T) | ||
|
||
// Dequeue 出队 | ||
Dequeue() []T | ||
Dequeue() T | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ import ( | |
"github.com/goexl/collection/internal/kernel" | ||
) | ||
|
||
// Queue 队列 | ||
type Queue[T any] = kernel.Queue[T] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package core | ||
|
||
import ( | ||
"container/list" | ||
|
||
"github.com/goexl/collection/internal/kernel" | ||
"github.com/goexl/collection/queue/internal/param" | ||
) | ||
|
||
var _ kernel.Queue[int] = (*Default[int])(nil) | ||
|
||
type Default[T any] struct { | ||
items *list.List | ||
params *param.Queue | ||
} | ||
|
||
func NewDefault[T any](params *param.Queue) *Default[T] { | ||
return &Default[T]{ | ||
items: list.New(), | ||
params: params, | ||
} | ||
} | ||
|
||
func (q *Default[T]) Enqueue(required T, optionals ...T) { | ||
q.enqueue(required) | ||
for _, optional := range optionals { | ||
q.enqueue(optional) | ||
} | ||
} | ||
|
||
func (q *Default[T]) Dequeue() (item T) { | ||
if 0 != q.items.Len() { | ||
element := q.items.Front() | ||
q.items.Remove(element) | ||
item = element.Value.(T) | ||
} | ||
|
||
return | ||
} | ||
|
||
func (q *Default[T]) Empty() bool { | ||
return 0 == q.items.Len() | ||
} | ||
|
||
func (q *Default[T]) Size() int { | ||
return q.items.Len() | ||
} | ||
|
||
func (q *Default[T]) enqueue(item T) { | ||
for q.params.Capacity > q.items.Len() { | ||
q.items.PushBack(item) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
package param | ||
|
||
import ( | ||
"math" | ||
) | ||
|
||
type Queue struct { | ||
Capacity int | ||
} | ||
|
||
func NewQueue() *Queue { | ||
return &Queue{ | ||
Capacity: 16, | ||
Capacity: math.MaxInt, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package queue_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/goexl/collection/queue" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNew(t *testing.T) { | ||
_queue := queue.New[int]().Build() | ||
require.NotNil(t, _queue, "默认队列创建出错") | ||
} |
This file was deleted.
Oops, something went wrong.