sigbits

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2021 License: MIT Imports: 1 Imported by: 1

Documentation

Overview

Package sigbits extracts significant bits from a sorted list of strings. Significant bits are the minimal bit set to distinguish all of the strings. E.g. we have 3 strings:

ab  // bin: 0110 0001 0110 0010
ac  // bin: 0110 0001 0110 0011
b   // bin: 0110 0010

The significant bits are [15, 7], which means the first different bits of "ab" and "ac" is the 15-th bit, and the 7-th bit for "ac" and "b".

Since 0.1.9

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FirstDiffBits

func FirstDiffBits(keys []string) []int32

FirstDiffBits find the first different bit position of every two adjacent keys.

Since 0.1.9

func ShardByPrefix added in v0.1.20

func ShardByPrefix(keys []string, maxSize int32) ([]int32, []int32)

ShardByPrefix splits a sorted string slice into shards each of which has at most maxSize elts.

The rule is that every shard has a unique prefix. All prefixes are still a sorted string slice.

It returns a slice of prefix lengths in bytes of each shard, and a slice of the starting index of each shard.

Since 0.1.20

Types

type SigBits

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

SigBits is a helper to get information about how many bits are required to distinguish a set of keys.

Since 0.1.9

func New

func New(keys []string) *SigBits

New creates a SigBits struct.

Since 0.1.9

func (*SigBits) CountPrefixes

func (sb *SigBits) CountPrefixes(keyStart, keyEnd, maxitem int32) (int32, []int32)

CountPrefies counts the number of n-bit prefix in a subset of keys [keyStart, keyEnd):

The first return value is the index of the first bit where there is a different bit among all keys. The second return values is a []int32 of maxitem + 1 elements. The ith element is the number of i-bits long prefix.

Since 0.1.9

Jump to

Keyboard shortcuts

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