cardinality

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 5 Imported by: 10

Documentation

Overview

Example (Bitmap64AndWrappedEmpty)
package main

import (
	"fmt"

	"github.com/specterops/dawgs/cardinality"
)

func main() {
	bitmap := cardinality.NewBitmap64With(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
	bitmap.And(cardinality.ThreadSafeDuplex(cardinality.NewBitmap64With(2, 4, 6)))

	fmt.Println(bitmap.Slice())
}
Output:
[2 4 6]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommutativeDuplexes added in v0.4.8

type CommutativeDuplexes[T uint32 | uint64] struct {
	// contains filtered or unexported fields
}

func (*CommutativeDuplexes[T]) And added in v0.4.8

func (s *CommutativeDuplexes[T]) And(dc DuplexCommutation[T])

func (*CommutativeDuplexes[T]) Contains added in v0.4.8

func (s *CommutativeDuplexes[T]) Contains(value T) bool

func (*CommutativeDuplexes[T]) Or added in v0.4.8

func (s *CommutativeDuplexes[T]) Or(dc DuplexCommutation[T])

type Duplex

type Duplex[T uint32 | uint64] interface {
	Provider[T]

	Xor(other Provider[T])
	And(other Provider[T])
	AndNot(other Provider[T])
	Remove(value T)
	Slice() []T
	Contains(value T) bool
	Each(delegate func(value T) bool)
	CheckedAdd(value T) bool
	Clone() Duplex[T]
}

Duplex is a two-way cardinality provider that allows a user to retrieve encoded values back out of the provider. This interface is suitable for algorithms that behave similar to bitvectors.

func NewBitmap32

func NewBitmap32() Duplex[uint32]

func NewBitmap32With

func NewBitmap32With(values ...uint32) Duplex[uint32]

func NewBitmap64

func NewBitmap64() Duplex[uint64]

func NewBitmap64With

func NewBitmap64With(values ...uint64) Duplex[uint64]

func ThreadSafeDuplex

func ThreadSafeDuplex[T uint32 | uint64](provider Duplex[T]) Duplex[T]

ThreadSafeDuplex synchronizes all operations of the wrapped Duplex with a single lock. Binary operations (Or, And, Xor, AndNot) snapshot another thread-safe wrapper before acquiring the receiver's lock, so opposing cross-wrapper operations and self-operations cannot form a lock-order cycle. Each operation is atomic for its receiver; there is no cross-operand atomicity, and a snapshot reflects the other wrapper only at the moment it was taken. Delegates passed to Each must not call back into the same wrapper.

type DuplexCommutation added in v0.4.8

type DuplexCommutation[T uint32 | uint64] []Duplex[T]

func CommutativeOr added in v0.4.8

func CommutativeOr[T uint32 | uint64](duplexes ...Duplex[T]) DuplexCommutation[T]

func (DuplexCommutation[T]) Contains added in v0.4.8

func (s DuplexCommutation[T]) Contains(value T) bool

func (DuplexCommutation[T]) Or added in v0.4.8

func (s DuplexCommutation[T]) Or(duplexes ...Duplex[T]) DuplexCommutation[T]

type DuplexConstructor

type DuplexConstructor[T uint32 | uint64] func() Duplex[T]

type Iterator

type Iterator[T uint32 | uint64] interface {
	HasNext() bool
	Next() T
}

Iterator allows enumeration of a duplex cardinality provider without requiring the allocation of the provider's set.

type Provider

type Provider[T uint32 | uint64] interface {
	Add(value ...T)
	Or(other Provider[T])
	Clear()
	Cardinality() uint64
}

Provider describes the most basic functionality of a cardinality provider algorithm: adding elements to the provider and producing the cardinality of those elements.

func CloneProvider

func CloneProvider[T uint32 | uint64](provider Provider[T]) Provider[T]

func NewBitmap32Provider

func NewBitmap32Provider() Provider[uint32]

func NewBitmap64Provider

func NewBitmap64Provider() Provider[uint64]

func NewHyperLogLog32Provider

func NewHyperLogLog32Provider() Provider[uint32]

func NewHyperLogLog64Provider

func NewHyperLogLog64Provider() Provider[uint64]

type ProviderConstructor

type ProviderConstructor[T uint32 | uint64] func() Provider[T]

type Simplex

type Simplex[T uint32 | uint64] interface {
	Provider[T]

	Clone() Simplex[T]
}

Simplex is a one-way cardinality provider that does not allow a user to retrieve encoded values back out of the provider. This interface is suitable for algorithms such as HyperLogLog which utilizes a hash function to merge identifiers into the cardinality provider.

func NewHyperLogLog32

func NewHyperLogLog32() Simplex[uint32]

func NewHyperLogLog64

func NewHyperLogLog64() Simplex[uint64]

func ThreadSafeSimplex

func ThreadSafeSimplex[T uint32 | uint64](provider Simplex[T]) Simplex[T]

ThreadSafeSimplex synchronizes all operations of the wrapped Simplex with a single lock. Or snapshots another thread-safe wrapper before acquiring the receiver's lock, so cross-wrapper merges cannot form a lock-order cycle and merge with a wrapped sketch reaches its implementation instead of being silently dropped by provider dispatch. There is no cross-operand atomicity.

type SimplexConstructor

type SimplexConstructor[T uint32 | uint64] func() Simplex[T]

Jump to

Keyboard shortcuts

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