https://github.com/wwwangxc/container
Various data structures implemented using Go.
https://github.com/wwwangxc/container
data-structures go golang
Last synced: 2 months ago
JSON representation
Various data structures implemented using Go.
- Host: GitHub
- URL: https://github.com/wwwangxc/container
- Owner: wwwangxc
- License: mit
- Created: 2022-10-25T08:24:20.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-18T01:43:22.000Z (almost 3 years ago)
- Last Synced: 2024-06-20T02:11:07.795Z (almost 2 years ago)
- Topics: data-structures, go, golang
- Language: Go
- Homepage:
- Size: 51.8 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.murphysec.com/dr/aDgidkK7d72WfN9WRi)
[](https://goreportcard.com/report/github.com/wwwangxc/container)
[](https://pkg.go.dev/github.com/wwwangxc/container)
Various data structures implemented using Go generics. 🤗
## Support
- [List](doc/list.md#list)
- [Array List](doc/list.md#array-list)
- [Singly Linked List](doc/list.md#singly-linked-list)
- [Doubly Linked List](doc/list.md#doubly-linked-list)
- [Set](doc/set.md#set)
- [Hash Set](doc/set.md#hash-set)
- [Map](doc/map.md#map)
- [Linked Map](doc/map.md#linked-map)
- [Heap](doc/heap.md#heap)
- [Min Heap](doc/heap.md#min-heap)
- [Max Heap](doc/heap.md#max-heap)
## Global Ability
### Container
It is the base feature provided by all data structures.
```go
// Container is the base feature provided by all data structures
type Container[T any] interface {
fmt.Stringer
// IsEmpty will return true when container has no element
IsEmpty() bool
// Size will return the number of elements in the container
Size() int
// Clear the elements inside the container
Clear()
// Values will return the collection of all element values in the container
Values() []T
}
```
### Enumerator
It provides enumerable functions for the containers.
```go
// Enumerator provides enumerable functions for the containers
type Enumerator[T comparable, U any] interface {
// Each calls the given function once for each element and passing that
// element's index(or key) and value
//
// Enter the next loop when it returns true
// Break loop when it returns false
Each(func(T, U) bool)
// Any calls the given function once for each element
//
// Return true if the given function returns true once
// Return false if the given function always returns false for all elements
Any(func(T, U) bool) bool
// All calls the given function once for each element
//
// Return true if the given function always returns true for all elements
// Return false if the given function returns false once
All(func(T, U) bool) bool
// First calls the given function once for each element
//
// Return [index(or key), value, true] when the given function return true
// for the first time
Find(func(T, U) bool) (T, U, bool)
// Select calls the given function once for each element
//
// It will return all elements for which the given function returns true
Select(func(T, U) bool) []U
}
```