data_structure

package
v0.0.0-...-10bc058 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DLinkedNode

type DLinkedNode struct {
	Key   int
	Value int
	Prev  *DLinkedNode
	Next  *DLinkedNode
}

双向链表

type LRUCache

type LRUCache struct {
	Capacity int
	Length   int
	Head     *DLinkedNode
	Tail     *DLinkedNode
	Nodes    map[int]*DLinkedNode
}

用一个辅助的头结点和尾结点

func Constructor

func Constructor(capacity int) LRUCache

func (*LRUCache) AddToHead

func (this *LRUCache) AddToHead(node *DLinkedNode)

func (*LRUCache) Get

func (this *LRUCache) Get(key int) int

func (*LRUCache) MoveToHead

func (this *LRUCache) MoveToHead(node *DLinkedNode)

移到头部

func (*LRUCache) Put

func (this *LRUCache) Put(key int, value int)

func (*LRUCache) RemoveNode

func (this *LRUCache) RemoveNode(node *DLinkedNode)

移除节点

func (*LRUCache) RemoveTail

func (this *LRUCache) RemoveTail() *DLinkedNode

移除尾结点

type ListNode

type ListNode struct {
	Key  interface{}
	Val  interface{}
	Next *ListNode
}

func (*ListNode) Del

func (l *ListNode) Del(key interface{})

func (*ListNode) Get

func (l *ListNode) Get(key interface{}) *ListNode

func (*ListNode) Insert

func (l *ListNode) Insert(key, val interface{})

type Map

type Map struct {
	Nodes []*ListNode
}

func NewMap

func NewMap(n int) *Map

func (*Map) Del

func (m *Map) Del(key interface{})

func (*Map) Get

func (m *Map) Get(key interface{}) interface{}

func (*Map) Store

func (m *Map) Store(key, val interface{})

type Trie

type Trie struct {
	IsEnd    bool
	Children map[int32]*Trie
}

func ConstructorTrie

func ConstructorTrie() Trie

func (*Trie) Insert

func (this *Trie) Insert(word string)

func (*Trie) Search

func (this *Trie) Search(word string) bool

func (*Trie) StartsWith

func (this *Trie) StartsWith(prefix string) bool

func (*Trie) Suggest

func (this *Trie) Suggest(prefix string) []string

先寻到 prefix 的最末,再把 prefix 加上所有的可能值给返回出来

Jump to

Keyboard shortcuts

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