mappedslice

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: MIT Imports: 4 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

mappedslice GoDoc Status Go Report Card Go Test Coverage

mappedslice is a Go library for efficient, memory map-backed slices. It provides a way to work with large datasets by mapping files directly into memory, allowing for fast and efficient access and manipulation of data. Ideal for applications needing high-performance data handling without loading entire files into RAM.

Features:

  • Memory-mapped slices for efficient file access
  • Supports large datasets with minimal memory overhead
  • Easy-to-use API for integrating with existing Go applications

Usage

New
func ExampleNew() {
	var err error
	if exampleSlice, err = New[int]("myfile.bat", 32); err != nil {
		// Handle error here
		return
	}
}
Slice.Get
func ExampleSlice_Get() {
	var (
		v   int
		err error
	)

	if v, err = exampleSlice.Get(0); err != nil {
		// Handle error here
		return
	}

	fmt.Println("Value", v)
}
Slice.Set
func ExampleSlice_Set() {
	var err error
	if err = exampleSlice.Set(0, 1337); err != nil {
		// Handle error here
		return
	}
}
Slice.Append
func ExampleSlice_Append() {
	var err error
	if err = exampleSlice.Append(1337); err != nil {
		// Handle error here
		return
	}
}
Slice.InsertAt
func ExampleSlice_InsertAt() {
	var err error
	if err = exampleSlice.InsertAt(0, 1337); err != nil {
		// Handle error here
		return
	}
}
Slice.RemoveAt
func ExampleSlice_RemoveAt() {
	var err error
	if err = exampleSlice.RemoveAt(0); err != nil {
		// Handle error here
		return
	}
}
Slice.ForEach
func ExampleSlice_ForEach() {
	exampleSlice.ForEach(func(v int) (end bool) {
		fmt.Println("Value", v)
		return
	})
}
Slice.Cursor

func ExampleSlice_Cursor() {
	cur := exampleSlice.Cursor()
	v, ok := cur.Seek(1337)
	if !ok {
		fmt.Println("index is missing")
		return
	}

	fmt.Println("My seek value!", v)

	for ok {
		v, ok = cur.Next()
		fmt.Println("My next value!", v)
	}
}
Slice.Cursor (using previous)
func ExampleSlice_Cursor_prev() {
	cur := exampleSlice.Cursor()
	v, ok := cur.Seek(1337)
	if !ok {
		fmt.Println("index is missing")
		return
	}

	fmt.Println("My seek value!", v)

	for ok {
		v, ok = cur.Prev()
		fmt.Println("My previous value!", v)
	}
}
Slice.Len
func ExampleSlice_Len() {
	fmt.Println("Length", exampleSlice.Len())
}
Slice.Slice
func ExampleSlice_Slice() {
	fmt.Println("Slice copy", exampleSlice.Slice())
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cursor added in v0.2.2

type Cursor[T any] interface {
	Seek(index int) (T, bool)
	Next() (T, bool)
	Prev() (T, bool)
	Close() error
}

type Slice

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

func New

func New[T any](filepath string, initialCapacity int64) (ref *Slice[T], err error)
Example
var err error
if exampleSlice, err = New[int]("myfile.bat", 32); err != nil {
	// Handle error here
	return
}

func (*Slice[T]) Append

func (s *Slice[T]) Append(t T) (err error)
Example
var err error
if err = exampleSlice.Append(1337); err != nil {
	// Handle error here
	return
}

func (*Slice[T]) Close

func (s *Slice[T]) Close() (err error)

func (*Slice[T]) Cursor added in v0.2.2

func (s *Slice[T]) Cursor() (out Cursor[T])
Example
cur := exampleSlice.Cursor()
v, ok := cur.Seek(1337)
if !ok {
	fmt.Println("index is missing")
	return
}

fmt.Println("My seek value!", v)

for ok {
	v, ok = cur.Next()
	fmt.Println("My next value!", v)
}
Example (Prev)
cur := exampleSlice.Cursor()
v, ok := cur.Seek(1337)
if !ok {
	fmt.Println("index is missing")
	return
}

fmt.Println("My seek value!", v)

for ok {
	v, ok = cur.Prev()
	fmt.Println("My previous value!", v)
}

func (*Slice[T]) ForEach

func (s *Slice[T]) ForEach(fn func(T) (end bool)) (ended bool)
Example
exampleSlice.ForEach(func(v int) (end bool) {
	fmt.Println("Value", v)
	return
})

func (*Slice[T]) Get

func (s *Slice[T]) Get(index int) (kv T, err error)
Example
var (
	v   int
	err error
)

if v, err = exampleSlice.Get(0); err != nil {
	// Handle error here
	return
}

fmt.Println("Value", v)

func (*Slice[T]) InsertAt

func (s *Slice[T]) InsertAt(index int, value T) (err error)
Example
var err error
if err = exampleSlice.InsertAt(0, 1337); err != nil {
	// Handle error here
	return
}

func (*Slice[T]) Len

func (s *Slice[T]) Len() int
Example
fmt.Println("Length", exampleSlice.Len())

func (*Slice[T]) RemoveAt

func (s *Slice[T]) RemoveAt(index int) (err error)
Example
var err error
if err = exampleSlice.RemoveAt(0); err != nil {
	// Handle error here
	return
}

func (*Slice[T]) Set

func (s *Slice[T]) Set(index int, t T) (err error)
Example
var err error
if err = exampleSlice.Set(0, 1337); err != nil {
	// Handle error here
	return
}

func (*Slice[T]) Slice

func (s *Slice[T]) Slice() (out []T)
Example
fmt.Println("Slice copy", exampleSlice.Slice())

Jump to

Keyboard shortcuts

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