bitmap

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: BSD-3-Clause Imports: 2 Imported by: 3 modules, 2 packages

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

Package bitmap

Abstract

bitmap stores membership flags for unsigned integer indexes in a growable, byte-backed bitmap. Set grows storage as needed; Has tests a bit and Del clears it.

API and limits

New accepts OptMaxIndex to choose initial capacity. Storage grows when Set reaches a larger index. The maximum supported index is the inclusive constant MaxIndex (1 << 34); Set silently ignores larger indexes, while Has returns false and Del does nothing for them.

Internal locking is enabled by default. OptDisableLock removes it; callers using that option MUST provide synchronization. Because the bounds check in Has and Del can overlap a resize, callers MUST externally serialize a Set that may grow the bitmap with concurrent reads or deletes. CopyTo copies the bit storage and the source's lock setting into the destination.

MarshalBinary returns the raw bitmap bytes without a versioned header. UnmarshalBinary replaces the receiver's contents and rejects empty or oversized data. The serialized bytes SHOULD be stored with any metadata needed to identify their meaning.

package main

import (
	"fmt"

	"go.osspkg.com/algorithms/structs/bitmap"
)

func main() {
	bm := bitmap.New(bitmap.OptMaxIndex(1024))
	bm.Set(42)
	fmt.Println(bm.Has(42)) // true
	bm.Del(42)
}

Documentation

Index

Constants

View Source
const (
	MaxIndex = uint64(1 << 34)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bitmap

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

func New

func New(opts ...Option) *Bitmap

func (*Bitmap) CopyTo added in v1.5.2

func (b *Bitmap) CopyTo(dst *Bitmap)

func (*Bitmap) Del

func (b *Bitmap) Del(index uint64)

func (*Bitmap) Has

func (b *Bitmap) Has(index uint64) bool

func (*Bitmap) MarshalBinary added in v1.5.3

func (b *Bitmap) MarshalBinary() ([]byte, error)

func (*Bitmap) Set

func (b *Bitmap) Set(index uint64)

func (*Bitmap) UnmarshalBinary added in v1.5.3

func (b *Bitmap) UnmarshalBinary(in []byte) error

type Option

type Option func(*Bitmap)

func OptDisableLock added in v1.5.3

func OptDisableLock() Option

func OptMaxIndex added in v1.5.3

func OptMaxIndex(index uint64) Option

Jump to

Keyboard shortcuts

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