container

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayStack

type ArrayStack[T any] struct {
	// contains filtered or unexported fields
}

ArrayStack represents a stack implementation using a slice

func (*ArrayStack[T]) Clear

func (s *ArrayStack[T]) Clear()

Clear removes all items from the stack

func (*ArrayStack[T]) Clone

func (s *ArrayStack[T]) Clone() Stack[T]

Clone creates a copy of the stack

func (*ArrayStack[T]) IsEmpty

func (s *ArrayStack[T]) IsEmpty() bool

IsEmpty returns true if the stack has no items

func (*ArrayStack[T]) Peek

func (s *ArrayStack[T]) Peek() (T, bool)

Peek returns the top item without removing it Returns zero value and false if stack is empty

func (*ArrayStack[T]) Pop

func (s *ArrayStack[T]) Pop() (T, bool)

Pop removes and returns the top item from the stack Returns zero value and false if stack is empty

func (*ArrayStack[T]) Push

func (s *ArrayStack[T]) Push(item T)

Push adds an item to the top of the stack

func (*ArrayStack[T]) Size

func (s *ArrayStack[T]) Size() int

Size returns the number of items in the stack

type Bitmap

type Bitmap interface {
	Set(bit uint64)
	Clear(bit uint64)
	Toggle(bit uint64)
	IsSet(bit uint64) bool
	IsAnySet(bits uint64) bool
	IsAllSet(bits uint64) bool
	Get() uint64
	SetAll()
	ClearAll()
	Count() int
	IsEmpty() bool
	IsFull() bool
	And(other Bitmap)
	Or(other Bitmap)
	Xor(other Bitmap)
	Not()
	Clone() Bitmap
	Equals(other Bitmap) bool
	String() string
	ToBinaryString() string
	ToHexString() string
	GetSetBits() []int
	SetBits(bits ...uint64)
	ClearBits(bits ...uint64)
	ToggleBits(bits ...uint64)
	IsSubset(other Bitmap) bool
	IsSuperset(other Bitmap) bool
	Intersection(other Bitmap) Bitmap
	Union(other Bitmap) Bitmap
	Difference(other Bitmap) Bitmap
	SymmetricDifference(other Bitmap) Bitmap
	ShiftLeft(n int)
	ShiftRight(n int)
	RotateLeft(n int)
	RotateRight(n int)
	GetLowestSetBit() int
	GetHighestSetBit() int
	NextSetBit(from int) int
	PrevSetBit(from int) int
}

Bitmap defines the interface for bitmap operations

func NewUint64Bitmap

func NewUint64Bitmap(initial uint64) Bitmap

NewUint64Bitmap creates a new bitmap with initial value

type DoublyLinkedList

type DoublyLinkedList[T any] struct {
	// contains filtered or unexported fields
}

DoublyLinkedList represents a doubly linked list implementation.

func (*DoublyLinkedList[T]) Append

func (l *DoublyLinkedList[T]) Append(items ...T)

Append adds multiple items to the back of the list.

func (*DoublyLinkedList[T]) AppendList

func (l *DoublyLinkedList[T]) AppendList(other List[T])

AppendList appends all items from another list to this list.

func (*DoublyLinkedList[T]) Back

func (l *DoublyLinkedList[T]) Back() (T, bool)

Back returns the back item without removing it.

func (*DoublyLinkedList[T]) Clear

func (l *DoublyLinkedList[T]) Clear()

Clear removes all items from the list.

func (*DoublyLinkedList[T]) Clone

func (l *DoublyLinkedList[T]) Clone() List[T]

Clone creates a shallow copy of the list.

func (*DoublyLinkedList[T]) ForEach

func (l *DoublyLinkedList[T]) ForEach(fn func(item T) bool)

ForEach iterates over all items in the list.

func (*DoublyLinkedList[T]) Front

func (l *DoublyLinkedList[T]) Front() (T, bool)

Front returns the front item without removing it.

func (*DoublyLinkedList[T]) GetAt

func (l *DoublyLinkedList[T]) GetAt(index int) (T, bool)

GetAt returns the item at the specified index.

func (*DoublyLinkedList[T]) InsertAt

func (l *DoublyLinkedList[T]) InsertAt(index int, item T) bool

InsertAt inserts an item at the specified index.

func (*DoublyLinkedList[T]) InsertBack

func (l *DoublyLinkedList[T]) InsertBack(item T)

InsertBack adds an item to the back of the list.

func (*DoublyLinkedList[T]) InsertFront

func (l *DoublyLinkedList[T]) InsertFront(item T)

InsertFront adds an item to the front of the list.

func (*DoublyLinkedList[T]) IsEmpty

func (l *DoublyLinkedList[T]) IsEmpty() bool

IsEmpty returns true if the list has no items.

func (*DoublyLinkedList[T]) RemoveAt

func (l *DoublyLinkedList[T]) RemoveAt(index int) (T, bool)

RemoveAt removes and returns the item at the specified index.

func (*DoublyLinkedList[T]) RemoveBack

func (l *DoublyLinkedList[T]) RemoveBack() (T, bool)

RemoveBack removes and returns the back item.

func (*DoublyLinkedList[T]) RemoveFront

func (l *DoublyLinkedList[T]) RemoveFront() (T, bool)

RemoveFront removes and returns the front item.

func (*DoublyLinkedList[T]) SetAt

func (l *DoublyLinkedList[T]) SetAt(index int, item T) bool

SetAt sets the item at the specified index.

func (*DoublyLinkedList[T]) Size

func (l *DoublyLinkedList[T]) Size() int

Size returns the number of items in the list.

func (*DoublyLinkedList[T]) ToSlice

func (l *DoublyLinkedList[T]) ToSlice() []T

ToSlice converts the list to a slice.

type DoublyNode

type DoublyNode[T any] struct {
	Value T
	Prev  *DoublyNode[T]
	Next  *DoublyNode[T]
}

DoublyNode represents a node in a doubly linked list.

type Heap

type Heap[T any] interface {
	Push(item T)
	Pop() (T, bool)
	Peek() (T, bool)
	IsEmpty() bool
	Size() int
	Clear()
	Clone() Heap[T]
	Type() HeapType
}

Heap defines the interface for heap operations

func Heapify

func Heapify[T cmp.Ordered](items []T, typ HeapType) Heap[T]

Heapify creates a heap from a slice of items

func HeapifyCustom

func HeapifyCustom[T any](items []T, less func(a, b T) bool, typ HeapType) Heap[T]

HeapifyCustom creates a heap from a slice of items with custom comparison

func NewHeap

func NewHeap[T any](less func(a, b T) bool, typ HeapType) Heap[T]

NewHeap creates a new heap with custom comparison function

func NewMaxHeap

func NewMaxHeap[T cmp.Ordered]() Heap[T]

NewMaxHeap creates a new max heap

func NewMinHeap

func NewMinHeap[T cmp.Ordered]() Heap[T]

NewMinHeap creates a new min heap

type HeapType

type HeapType int

HeapType defines the type of heap

const (
	MinHeap HeapType = iota
	MaxHeap
)

type List

type List[T any] interface {
	// Basic operations
	InsertFront(item T)
	InsertBack(item T)
	InsertAt(index int, item T) bool
	RemoveFront() (T, bool)
	RemoveBack() (T, bool)
	RemoveAt(index int) (T, bool)
	GetAt(index int) (T, bool)
	SetAt(index int, item T) bool

	// Utility operations
	IsEmpty() bool
	Size() int
	Clear()
	Clone() List[T]

	// Iterator operations
	Front() (T, bool)
	Back() (T, bool)
	ForEach(fn func(item T) bool)

	// Slice operations
	Append(items ...T)
	ToSlice() []T
	AppendList(other List[T])
}

List defines the interface for linked list operations.

func NewDoublyLinkedList

func NewDoublyLinkedList[T any]() List[T]

NewDoublyLinkedList creates a new empty doubly linked list.

func NewSinglyLinkedList

func NewSinglyLinkedList[T any]() List[T]

NewSinglyLinkedList creates a new empty singly linked list.

type MapSet

type MapSet[T comparable] struct {
	// contains filtered or unexported fields
}

MapSet represents a set implementation using a map

func (*MapSet[T]) Add

func (s *MapSet[T]) Add(item T)

Add adds an item to the set

func (*MapSet[T]) Clear

func (s *MapSet[T]) Clear()

Clear removes all items from the set

func (*MapSet[T]) Clone

func (s *MapSet[T]) Clone() Set[T]

Clone returns a new set with the same items as this set

func (*MapSet[T]) Contains

func (s *MapSet[T]) Contains(item T) bool

Contains returns true if the item is in the set

func (*MapSet[T]) Difference

func (s *MapSet[T]) Difference(other Set[T]) Set[T]

Difference returns a new set containing items that exist in this set but not in the other

func (*MapSet[T]) Intersection

func (s *MapSet[T]) Intersection(other Set[T]) Set[T]

Intersection returns a new set containing items that exist in both sets

func (*MapSet[T]) IsEmpty

func (s *MapSet[T]) IsEmpty() bool

IsEmpty returns true if the set has no items

func (*MapSet[T]) Items

func (s *MapSet[T]) Items() []T

Items returns all items in the set as a slice

func (*MapSet[T]) Remove

func (s *MapSet[T]) Remove(item T)

Remove removes an item from the set

func (*MapSet[T]) Size

func (s *MapSet[T]) Size() int

Size returns the number of items in the set

func (*MapSet[T]) Union

func (s *MapSet[T]) Union(other Set[T]) Set[T]

Union returns a new set containing all items from both sets

type Node

type Node[T any] struct {
	Value T
	Next  *Node[T]
}

Node represents a node in a singly linked list.

type Queue

type Queue[T any] interface {
	Enqueue(item T)
	Dequeue() (T, bool)
	Peek() (T, bool)
	IsEmpty() bool
	Size() int
	Clear()
	Clone() Queue[T]
}

Queue defines the interface for queue operations (FIFO).

func NewSliceQueue

func NewSliceQueue[T any]() Queue[T]

NewSliceQueue creates a new empty queue.

type Set

type Set[T comparable] interface {
	Add(item T)
	Remove(item T)
	Contains(item T) bool
	IsEmpty() bool
	Size() int
	Clear()
	Items() []T
	Union(other Set[T]) Set[T]
	Intersection(other Set[T]) Set[T]
	Difference(other Set[T]) Set[T]
	Clone() Set[T]
}

Set defines the interface for set operations

func NewMapSet

func NewMapSet[T comparable]() Set[T]

NewMapSet creates a new empty set

type SinglyLinkedList

type SinglyLinkedList[T any] struct {
	// contains filtered or unexported fields
}

SinglyLinkedList represents a singly linked list implementation.

func (*SinglyLinkedList[T]) Append

func (l *SinglyLinkedList[T]) Append(items ...T)

Append adds multiple items to the back of the list.

func (*SinglyLinkedList[T]) AppendList

func (l *SinglyLinkedList[T]) AppendList(other List[T])

AppendList appends all items from another list to this list.

func (*SinglyLinkedList[T]) Back

func (l *SinglyLinkedList[T]) Back() (T, bool)

Back returns the back item without removing it.

func (*SinglyLinkedList[T]) Clear

func (l *SinglyLinkedList[T]) Clear()

Clear removes all items from the list.

func (*SinglyLinkedList[T]) Clone

func (l *SinglyLinkedList[T]) Clone() List[T]

Clone creates a shallow copy of the list.

func (*SinglyLinkedList[T]) ForEach

func (l *SinglyLinkedList[T]) ForEach(fn func(item T) bool)

ForEach iterates over all items in the list.

func (*SinglyLinkedList[T]) Front

func (l *SinglyLinkedList[T]) Front() (T, bool)

Front returns the front item without removing it.

func (*SinglyLinkedList[T]) GetAt

func (l *SinglyLinkedList[T]) GetAt(index int) (T, bool)

GetAt returns the item at the specified index.

func (*SinglyLinkedList[T]) InsertAt

func (l *SinglyLinkedList[T]) InsertAt(index int, item T) bool

InsertAt inserts an item at the specified index.

func (*SinglyLinkedList[T]) InsertBack

func (l *SinglyLinkedList[T]) InsertBack(item T)

InsertBack adds an item to the back of the list.

func (*SinglyLinkedList[T]) InsertFront

func (l *SinglyLinkedList[T]) InsertFront(item T)

InsertFront adds an item to the front of the list.

func (*SinglyLinkedList[T]) IsEmpty

func (l *SinglyLinkedList[T]) IsEmpty() bool

IsEmpty returns true if the list has no items.

func (*SinglyLinkedList[T]) RemoveAt

func (l *SinglyLinkedList[T]) RemoveAt(index int) (T, bool)

RemoveAt removes and returns the item at the specified index.

func (*SinglyLinkedList[T]) RemoveBack

func (l *SinglyLinkedList[T]) RemoveBack() (T, bool)

RemoveBack removes and returns the back item.

func (*SinglyLinkedList[T]) RemoveFront

func (l *SinglyLinkedList[T]) RemoveFront() (T, bool)

RemoveFront removes and returns the front item.

func (*SinglyLinkedList[T]) SetAt

func (l *SinglyLinkedList[T]) SetAt(index int, item T) bool

SetAt sets the item at the specified index.

func (*SinglyLinkedList[T]) Size

func (l *SinglyLinkedList[T]) Size() int

Size returns the number of items in the list.

func (*SinglyLinkedList[T]) ToSlice

func (l *SinglyLinkedList[T]) ToSlice() []T

ToSlice converts the list to a slice.

type SliceHeap

type SliceHeap[T any] struct {
	// contains filtered or unexported fields
}

SliceHeap represents a heap implementation using a slice

func (*SliceHeap[T]) Clear

func (h *SliceHeap[T]) Clear()

Clear removes all items from the heap

func (*SliceHeap[T]) Clone

func (h *SliceHeap[T]) Clone() Heap[T]

Clone creates a copy of the heap

func (*SliceHeap[T]) IsEmpty

func (h *SliceHeap[T]) IsEmpty() bool

IsEmpty returns true if the heap has no items

func (*SliceHeap[T]) Peek

func (h *SliceHeap[T]) Peek() (T, bool)

Peek returns the top item without removing it Returns zero value and false if heap is empty

func (*SliceHeap[T]) Pop

func (h *SliceHeap[T]) Pop() (T, bool)

Pop removes and returns the top item from the heap Returns zero value and false if heap is empty

func (*SliceHeap[T]) Push

func (h *SliceHeap[T]) Push(item T)

Push adds an item to the heap

func (*SliceHeap[T]) Size

func (h *SliceHeap[T]) Size() int

Size returns the number of items in the heap

func (*SliceHeap[T]) Type

func (h *SliceHeap[T]) Type() HeapType

Type returns the type of the heap (MinHeap or MaxHeap)

type SliceQueue

type SliceQueue[T any] struct {
	// contains filtered or unexported fields
}

SliceQueue represents a queue implementation using a slice.

func (*SliceQueue[T]) Clear

func (q *SliceQueue[T]) Clear()

Clear removes all items from the queue.

func (*SliceQueue[T]) Clone

func (q *SliceQueue[T]) Clone() Queue[T]

Clone creates a shallow copy of the queue.

func (*SliceQueue[T]) Dequeue

func (q *SliceQueue[T]) Dequeue() (T, bool)

Dequeue removes and returns the item from the front of the queue. Returns zero value and false if the queue is empty.

func (*SliceQueue[T]) Enqueue

func (q *SliceQueue[T]) Enqueue(item T)

Enqueue adds an item to the end of the queue.

func (*SliceQueue[T]) IsEmpty

func (q *SliceQueue[T]) IsEmpty() bool

IsEmpty returns true if the queue has no items.

func (*SliceQueue[T]) Peek

func (q *SliceQueue[T]) Peek() (T, bool)

Peek returns the front item without removing it. Returns zero value and false if the queue is empty.

func (*SliceQueue[T]) Size

func (q *SliceQueue[T]) Size() int

Size returns the number of items in the queue.

type Stack

type Stack[T any] interface {
	Push(item T)
	Pop() (T, bool)
	Peek() (T, bool)
	IsEmpty() bool
	Size() int
	Clear()
	Clone() Stack[T]
}

Stack defines the interface for stack operations

func NewArrayStack

func NewArrayStack[T any]() Stack[T]

NewArrayStack creates a new empty stack

type Uint64Bitmap

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

Uint64Bitmap represents a bitmap implementation using uint64

func (*Uint64Bitmap) And

func (b *Uint64Bitmap) And(other Bitmap)

And performs bitwise AND with another bitmap

func (*Uint64Bitmap) Clear

func (b *Uint64Bitmap) Clear(bit uint64)

Clear disables a specific bit

func (*Uint64Bitmap) ClearAll

func (b *Uint64Bitmap) ClearAll()

ClearAll disables all bits

func (*Uint64Bitmap) ClearBits

func (b *Uint64Bitmap) ClearBits(bits ...uint64)

ClearBits clears multiple bits at once

func (*Uint64Bitmap) Clone

func (b *Uint64Bitmap) Clone() Bitmap

Clone creates a copy of the bitmap

func (*Uint64Bitmap) Count

func (b *Uint64Bitmap) Count() int

Count returns the number of set bits

func (*Uint64Bitmap) Difference

func (b *Uint64Bitmap) Difference(other Bitmap) Bitmap

Difference returns the difference with another bitmap

func (*Uint64Bitmap) Equals

func (b *Uint64Bitmap) Equals(other Bitmap) bool

Equals checks if two bitmaps are equal

func (*Uint64Bitmap) Get

func (b *Uint64Bitmap) Get() uint64

Get returns the current bitmap value

func (*Uint64Bitmap) GetHighestSetBit

func (b *Uint64Bitmap) GetHighestSetBit() int

GetHighestSetBit returns the position of the highest set bit

func (*Uint64Bitmap) GetLowestSetBit

func (b *Uint64Bitmap) GetLowestSetBit() int

GetLowestSetBit returns the position of the lowest set bit

func (*Uint64Bitmap) GetSetBits

func (b *Uint64Bitmap) GetSetBits() []int

GetSetBits returns a slice of bit positions that are set

func (*Uint64Bitmap) Intersection

func (b *Uint64Bitmap) Intersection(other Bitmap) Bitmap

Intersection returns the intersection with another bitmap

func (*Uint64Bitmap) IsAllSet

func (b *Uint64Bitmap) IsAllSet(bits uint64) bool

IsAllSet checks if all of the given bits are enabled

func (*Uint64Bitmap) IsAnySet

func (b *Uint64Bitmap) IsAnySet(bits uint64) bool

IsAnySet checks if any of the given bits are enabled

func (*Uint64Bitmap) IsEmpty

func (b *Uint64Bitmap) IsEmpty() bool

IsEmpty returns true if no bits are set

func (*Uint64Bitmap) IsFull

func (b *Uint64Bitmap) IsFull() bool

IsFull returns true if all bits are set

func (*Uint64Bitmap) IsSet

func (b *Uint64Bitmap) IsSet(bit uint64) bool

IsSet checks if a specific bit is enabled

func (*Uint64Bitmap) IsSubset

func (b *Uint64Bitmap) IsSubset(other Bitmap) bool

IsSubset checks if this bitmap is a subset of another

func (*Uint64Bitmap) IsSuperset

func (b *Uint64Bitmap) IsSuperset(other Bitmap) bool

IsSuperset checks if this bitmap is a superset of another

func (*Uint64Bitmap) NextSetBit

func (b *Uint64Bitmap) NextSetBit(from int) int

NextSetBit returns the next set bit after the given position

func (*Uint64Bitmap) Not

func (b *Uint64Bitmap) Not()

Not performs bitwise NOT

func (*Uint64Bitmap) Or

func (b *Uint64Bitmap) Or(other Bitmap)

Or performs bitwise OR with another bitmap

func (*Uint64Bitmap) PrevSetBit

func (b *Uint64Bitmap) PrevSetBit(from int) int

PrevSetBit returns the previous set bit before the given position

func (*Uint64Bitmap) RotateLeft

func (b *Uint64Bitmap) RotateLeft(n int)

RotateLeft rotates bits to the left by n positions

func (*Uint64Bitmap) RotateRight

func (b *Uint64Bitmap) RotateRight(n int)

RotateRight rotates bits to the right by n positions

func (*Uint64Bitmap) Set

func (b *Uint64Bitmap) Set(bit uint64)

Set enables a specific bit

func (*Uint64Bitmap) SetAll

func (b *Uint64Bitmap) SetAll()

SetAll enables all bits

func (*Uint64Bitmap) SetBits

func (b *Uint64Bitmap) SetBits(bits ...uint64)

SetBits sets multiple bits at once

func (*Uint64Bitmap) ShiftLeft

func (b *Uint64Bitmap) ShiftLeft(n int)

ShiftLeft shifts bits to the left by n positions

func (*Uint64Bitmap) ShiftRight

func (b *Uint64Bitmap) ShiftRight(n int)

ShiftRight shifts bits to the right by n positions

func (*Uint64Bitmap) String

func (b *Uint64Bitmap) String() string

String returns a string representation of the bitmap

func (*Uint64Bitmap) SymmetricDifference

func (b *Uint64Bitmap) SymmetricDifference(other Bitmap) Bitmap

SymmetricDifference returns the symmetric difference with another bitmap

func (*Uint64Bitmap) ToBinaryString

func (b *Uint64Bitmap) ToBinaryString() string

ToBinaryString returns binary representation

func (*Uint64Bitmap) ToHexString

func (b *Uint64Bitmap) ToHexString() string

ToHexString returns hexadecimal representation

func (*Uint64Bitmap) Toggle

func (b *Uint64Bitmap) Toggle(bit uint64)

Toggle toggles a specific bit

func (*Uint64Bitmap) ToggleBits

func (b *Uint64Bitmap) ToggleBits(bits ...uint64)

ToggleBits toggles multiple bits at once

func (*Uint64Bitmap) Union

func (b *Uint64Bitmap) Union(other Bitmap) Bitmap

Union returns the union with another bitmap

func (*Uint64Bitmap) Xor

func (b *Uint64Bitmap) Xor(other Bitmap)

Xor performs bitwise XOR with another bitmap

Jump to

Keyboard shortcuts

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