bitmap

package
v1.1.0-beta.0...-cc83417 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 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 ConcurrentBitmap

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

ConcurrentBitmap is a static-length bitmap which is thread-safe on setting. It is implemented using CAS, as atomic bitwise operation is not supported by golang yet. (See https://github.com/golang/go/issues/24244) CAS operation is narrowed down to uint32 instead of longer types like uint64, to reduce probability of racing.

func NewConcurrentBitmap

func NewConcurrentBitmap(bitLen int) *ConcurrentBitmap

NewConcurrentBitmap initializes a ConcurrentBitmap which can store bitLen of bits.

func (*ConcurrentBitmap) BytesConsumed

func (cb *ConcurrentBitmap) BytesConsumed() int64

BytesConsumed returns size of this bitmap in bytes.

func (*ConcurrentBitmap) Clone

func (cb *ConcurrentBitmap) Clone() *ConcurrentBitmap

Clone clones a new bitmap with the old bit set.

func (*ConcurrentBitmap) Reset

func (cb *ConcurrentBitmap) Reset(bitLen int)

Reset clean the bitmap if the length is suitable, otherwise renewing one.

func (*ConcurrentBitmap) Set

func (cb *ConcurrentBitmap) Set(bitIndex int) (isSetter bool)

Set sets the bit on bitIndex to be 1 (bitIndex starts from 0). isSetter indicates whether the function call this time triggers the bit from 0 to 1. bitIndex bigger than bitLen initialized will be ignored.

func (*ConcurrentBitmap) UnsafeIsSet

func (cb *ConcurrentBitmap) UnsafeIsSet(bitIndex int) (isSet bool)

UnsafeIsSet returns if a bit on bitIndex is set (bitIndex starts from 0). bitIndex bigger than bitLen initialized will return false. This method is not thread-safe as it does not use atomic load.

func (*ConcurrentBitmap) UnsafeSet

func (cb *ConcurrentBitmap) UnsafeSet(bitIndex int)

UnsafeSet sets the bit on bitIndex to be 1 (bitIndex starts from 0). isSetter indicates whether the function call this time triggers the bit from 0 to 1. bitIndex bigger than bitLen initialized will be ignored. (this version is concurrent unsafe if the caller can make sure write is in single thread)

Jump to

Keyboard shortcuts

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