Documentation
¶
Overview ¶
Package sslice provides functionalities for creating a slice which is always sorted.
Index ¶
- type Int
- type Int32
- type Int64
- type SortableElement
- type SortedSlice
- func (ss *SortedSlice) Cap() int
- func (ss *SortedSlice) Contains(elem SortableElement) bool
- func (ss *SortedSlice) Get(i int) SortableElement
- func (ss *SortedSlice) IndexOf(elem SortableElement) int
- func (ss *SortedSlice) Iter(fn func(int, SortableElement) bool)
- func (ss *SortedSlice) LastIndexOf(elem SortableElement) int
- func (ss *SortedSlice) Len() int
- func (ss *SortedSlice) Merge(other SortedSlice)
- func (ss *SortedSlice) Pop() (elem SortableElement)
- func (ss *SortedSlice) Push(elems ...SortableElement)
- func (ss *SortedSlice) Remove(i uint64)
- func (ss *SortedSlice) Reverse()
- func (ss *SortedSlice) Shift() (elem SortableElement)
- type String
- type Uint
- type Uint32
- type Uint64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Int ¶
type Int int
Int is an alias to int which implements `SortableElement`
func (Int) Compare ¶ added in v0.3.0
func (i Int) Compare(other SortableElement) int
Compare implements `Compare` method of `SortableElement`
type Int32 ¶
type Int32 int32
Int32 is an alias to int32 which implements `SortableElement`
func (Int32) Compare ¶ added in v0.3.0
func (i Int32) Compare(other SortableElement) int
Compare implements `Compare` method of `SortableElement`
type Int64 ¶
type Int64 int64
Int64 is an alias to int64 which implements `SortableElement`
func (Int64) Compare ¶ added in v0.3.0
func (i Int64) Compare(other SortableElement) int
Compare implements `Compare` method of `SortableElement`
type SortableElement ¶
type SortableElement interface { // Compare compares two SortableElement (`receiver` and `other`) // // Returns: // * `1` if `receiver` is greater than `other` // * `-1` if `other` is greater than `receiver` // * `0` if `receiver` equals `other` Compare(other SortableElement) int }
SortableElement represents an interface to be implemented for elements of `SortedSlice`
type SortedSlice ¶
type SortedSlice struct {
// contains filtered or unexported fields
}
SortedSlice represents a slice which is always sorted.
func (*SortedSlice) Contains ¶ added in v0.2.0
func (ss *SortedSlice) Contains(elem SortableElement) bool
Contains returns true if `ss` containbs `elem`
func (*SortedSlice) Get ¶
func (ss *SortedSlice) Get(i int) SortableElement
Get returns the element at index `i`
func (*SortedSlice) IndexOf ¶ added in v0.2.0
func (ss *SortedSlice) IndexOf(elem SortableElement) int
IndexOf returns the first occurrence index of `elem` in `ss` or -1 if `ss` does not contain `elem`
func (*SortedSlice) Iter ¶
func (ss *SortedSlice) Iter(fn func(int, SortableElement) bool)
Iter returns the inner slice of SortedSlice. A false return value of `fn` will break the loop.
func (*SortedSlice) LastIndexOf ¶ added in v0.2.0
func (ss *SortedSlice) LastIndexOf(elem SortableElement) int
LastIndexOf returns the last occurrence index of `elem` in `ss` or -1 if `ss` does not contain `elem`
func (*SortedSlice) Merge ¶
func (ss *SortedSlice) Merge(other SortedSlice)
Merge merges `other` to `ss`
func (*SortedSlice) Pop ¶
func (ss *SortedSlice) Pop() (elem SortableElement)
Pop removes the last elemt and returns it
func (*SortedSlice) Push ¶
func (ss *SortedSlice) Push(elems ...SortableElement)
Push appends `elems` to sorted slice of `ss`
func (*SortedSlice) Remove ¶
func (ss *SortedSlice) Remove(i uint64)
Remove removes an element at the index `i`
func (*SortedSlice) Shift ¶
func (ss *SortedSlice) Shift() (elem SortableElement)
Shift removes the first elemt and returns it
type String ¶
type String string
String is an alias to string which implements `SortableElement`
func (String) Compare ¶ added in v0.3.0
func (s String) Compare(other SortableElement) int
Compare implements `Compare` method of `SortableElement`
type Uint ¶
type Uint uint
Uint is an alias to uint which implements `SortableElement`
func (Uint) Compare ¶ added in v0.3.0
func (u Uint) Compare(other SortableElement) int
Compare implements `Compare` method of `SortableElement`