https://github.com/majornick/orderedset
Ordered Set, from classic STL, with functions like Lower-Bound and Bsearch. Every "Big" Operation works in log(n).
https://github.com/majornick/orderedset
golang orderedset set stl-containers
Last synced: about 1 month ago
JSON representation
Ordered Set, from classic STL, with functions like Lower-Bound and Bsearch. Every "Big" Operation works in log(n).
- Host: GitHub
- URL: https://github.com/majornick/orderedset
- Owner: MajorNick
- Created: 2022-11-27T01:33:08.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-11T19:15:21.000Z (almost 3 years ago)
- Last Synced: 2024-10-31T04:03:53.089Z (over 1 year ago)
- Topics: golang, orderedset, set, stl-containers
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ordered Set
## Ordered Set from Classic STL.
### Writen using empty interfaces. So it can called Generics without actual Generics.
### Pros: every "Big" method works in O(log(n)) complexity and can be used on all types
### Cons: Regardless of whether it is primitive or not, you have to give NewSet() Compare function.
### And Also after inserting struct type in set and you need type assertion after getting element from Set.
### Example compare function for Integers:
```
cmp := func (a,b interface{}) int {
a1 := a.(int)
b1 := b.(int)
if a1 == b1 {
return 0
}
if(a1>b1){
return 1
}
return -1
}
st := NewSet(cmp)
```
### Internal structure is
```
type orderedSet struct{
set []interface{}
size int
cmp func(a, b interface{}) int
}
```
### So if you want to get element from set use (your Set).Get("index")