Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

list source pure

Package list implements a dynamic list data structure backed by a B+ tree. It provides O(log n) operations for most l...

Overview

Package list implements a dynamic list data structure backed by a B+ tree. It provides O(log n) operations for most list operations while maintaining order stability.

The list supports various operations including append, get, set, delete, range queries, and iteration. It can store values of any type.

Example usage:

Example
 1// Create a new list and add elements
 2var l list.List
 3l.Append(1, 2, 3)
 4
 5// Get and set elements
 6value, _ := l.Get(1)  // returns 2
 7l.Set(1, 42)      // updates index 1 to 42
 8
 9// Delete elements
10l.Delete(0)       // removes first element
11
12// Iterate over elements
13l.ForEach(func(index int, value any) bool {
14    ufmt.Printf("index %d: %v\n", index, value)
15    return false  // continue iteration
16})
17// Output:
18// index 0: 42
19// index 1: 3
20
21// Create a list using a variable declaration
22var l2 list.List
23l2.Append(4, 5, 6)
24println(l2.Len())  // Output: 3

Types 2

type IList

interface
 1type IList interface {
 2	Len() int
 3	Append(values ...any)
 4	Get(index int) (any, bool)
 5	Set(index int, value any) bool
 6	Delete(index int) (any, bool)
 7	Slice(startIndex, endIndex int) []any
 8	ForEach(fn func(index int, value any) bool)
 9	Clone() *List
10	DeleteRange(startIndex, endIndex int) int
11}
source

IList defines the interface for list operations

type List

struct
1type List struct {
2	tree  bptree.BPTree
3	idGen seqid.ID
4}
source

List represents an ordered sequence of items backed by a B+ tree

Methods on List

func Append

method on List
1func (l *List) Append(values ...any)
source

Append adds one or more values to the end of the list.

func Clone

method on List
1func (l *List) Clone() *List
source

Clone creates a shallow copy of the list.

func Delete

method on List
1func (l *List) Delete(index int) (any, bool)
source

Delete removes the element at the specified index. Returns the deleted value and true if successful, nil and false otherwise.

func DeleteRange

method on List
1func (l *List) DeleteRange(startIndex, endIndex int) int
source

DeleteRange removes elements from startIndex (inclusive) to endIndex (exclusive). Returns the number of elements deleted.

func ForEach

method on List
1func (l *List) ForEach(fn func(index int, value any) bool)
source

ForEach iterates through all elements in the list.

func Get

method on List
1func (l *List) Get(index int) (any, bool)
source

Get returns the value at the specified index and true if the index is valid. Returns (nil, false) if index is out of bounds.

func Len

method on List
1func (l *List) Len() int
source

Len returns the number of elements in the list.

func Set

method on List
1func (l *List) Set(index int, value any) bool
source

Set updates or appends a value at the specified index. Returns true if the operation was successful, false otherwise. For empty lists, only index 0 is valid (append case).

func Slice

method on List
1func (l *List) Slice(startIndex, endIndex int) []any
source

Slice returns a slice of values from startIndex (inclusive) to endIndex (exclusive). Returns nil if the range is invalid.

func Tree

method on List
1func (l *List) Tree() *rotree.ReadOnlyTree
source

Tree returns a read-only pointer to the underlying B+ tree.

Imports 3

Source Files 3