ds

package
v0.0.0-...-b044761 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LRU

type LRU struct {
	// contains filtered or unexported fields
}

LRU ...

func NewLRU

func NewLRU(capacity int) LRU

NewLRU ...

func (*LRU) Get

func (l *LRU) Get(key int) int

Get ...

func (*LRU) Put

func (l *LRU) Put(key int, value int)

Put ...

type MinStack

type MinStack struct {
	// contains filtered or unexported fields
}

MinStack ...

func NewMinStack

func NewMinStack() MinStack

NewMinStack ...

func (*MinStack) GetMin

func (ms *MinStack) GetMin() int

GetMin ...

func (*MinStack) Pop

func (ms *MinStack) Pop()

Pop ...

func (*MinStack) Push

func (ms *MinStack) Push(x int)

Push ...

func (*MinStack) Top

func (ms *MinStack) Top() int

Top ...

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node ...

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue is a FIFO queue

func NewQueue

func NewQueue() *Queue

NewQueue returns a queue

func (*Queue) Dequeue

func (q *Queue) Dequeue() interface{}

Dequeue dequeues a value from the head of queue

func (*Queue) Enqueue

func (q *Queue) Enqueue(v interface{})

Enqueue enqueues a value to the tail of queue

type RBTree

type RBTree struct {
	// contains filtered or unexported fields
}

RBTree is a red-black tree

func NewRBTree

func NewRBTree(less common.Less) *RBTree

NewRBTree creates a red-black tree

func (*RBTree) Del

func (t *RBTree) Del(key interface{})

Del deletes the stored value by given key

func (*RBTree) Get

func (t *RBTree) Get(key interface{}) interface{}

Get returns the stored value by given key

func (*RBTree) Len

func (t *RBTree) Len() int

Len returns the size of the tree

func (*RBTree) Put

func (t *RBTree) Put(key, value interface{})

Put stores the value by given key

func (*RBTree) String

func (t *RBTree) String() string

type RandomizedSet

type RandomizedSet struct {
	// contains filtered or unexported fields
}

RandomizedSet implements O(1) randomized set

func NewRandomizedSet

func NewRandomizedSet() RandomizedSet

NewRandomizedSet ...

func (*RandomizedSet) Get

func (rs *RandomizedSet) Get() int

Get gets a random element from the set.

func (*RandomizedSet) Insert

func (rs *RandomizedSet) Insert(val int) bool

Insert inserts a value to the set. Returns true if the set did not already contain the specified element.

func (*RandomizedSet) Remove

func (rs *RandomizedSet) Remove(val int) bool

Remove removes a value from the set. Returns true if the set contained the specified element.

type RingBuffer

type RingBuffer struct {
	// contains filtered or unexported fields
}

RingBuffer implements ring buffer queue

func NewRingBuffer

func NewRingBuffer(capacity int) *RingBuffer

NewRingBuffer creates a ring buffer with given capacity

func (*RingBuffer) Get

func (rb *RingBuffer) Get() (x interface{})

Get gets the first element from queue

func (*RingBuffer) IsFull

func (rb *RingBuffer) IsFull() bool

IsFull checks if the ring buffer is full

func (*RingBuffer) LookAll

func (rb *RingBuffer) LookAll() []interface{}

LookAll reads all elements from ring buffer this method doesn't consume all elements

func (*RingBuffer) Put

func (rb *RingBuffer) Put(x interface{}) (ok bool)

Put puts x into ring buffer

type SkipList

type SkipList struct {
	MaxLevel int
	// contains filtered or unexported fields
}

A SkipList maintains an ordered collection of key:valkue pairs. It support insertion, lookup, and deletion operations with O(log n) time complexity Paper: Pugh, William (June 1990). "Skip lists: a probabilistic alternative to balanced trees". Communications of the ACM 33 (6): 668–676

func NewSkipList

func NewSkipList(less common.Less) *SkipList

NewSkipList returns a skiplist.

func (*SkipList) Del

func (s *SkipList) Del(k interface{}) (v interface{}, ok bool)

Del returns the deleted value if ok

func (*SkipList) Get

func (s *SkipList) Get(k interface{}) (v interface{}, ok bool)

Get returns corresponding v with given k.

func (*SkipList) Len

func (s *SkipList) Len() int

Len returns the length of given skiplist.

func (*SkipList) Range

func (s *SkipList) Range(from, to interface{}, op func(v interface{}))

Range interates `from` to `to` with `op`.

func (*SkipList) Search

func (s *SkipList) Search(k interface{}) (ok bool)

Search returns true if k is founded in the skiplist.

func (*SkipList) Set

func (s *SkipList) Set(k interface{}, v interface{})

Set sets given k and v pair into the skiplist.

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

Stack is a FILO stack

func NewStack

func NewStack() *Stack

NewStack returns a new stack

func (*Stack) Pop

func (s *Stack) Pop() interface{}

Pop pops the top value out of the stack

func (*Stack) Push

func (s *Stack) Push(v interface{})

Push pushes a value to the stack

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL