Static bit vector structures in Go

Overview

teivah/bitvector

Go Report Card

Overview

A bit vector is an array data structure that compactly stores bits.

This library is based on 5 static different data structures:

  • 8-bit vector: relies on an internal uint8
  • 16-bit vector: relies on an internal uint16
  • 32-bit vector: relies on an internal uint32
  • 64-bit vector: relies on an internal uint64
  • 128-bit vector: relies on two internal uint64 (for ASCII problems)

The rationale of using a static integer compared to a dynamic []byte is first of all to save memory. There is no structure and/or slice overhead. Hence, you might be interested in this library for memory-bound computation.

Also, the operations (get, set, etc.) are way more efficient. A simple benchmark shows that it's about 10 times more efficient than using a byte slice. Moreover, there is a guarantee that the internal bit vectors will not escape to the heap and remain only at the stack level.

Yet, the only drawback is to have a fixed-size bit vector (8, 16, 32, 64 or 128). If you require a dynamic bit vector, you should take a look at dropbox/godropbox for example.

Installation

go get github.com/teivah/bitvector

Documentation

Initialization

  • 8-bit vector:
var bv bitvector.Len8
  • 16-bit vector:
var bv bitvector.Len16
  • 32-bit vector:
var bv bitvector.Len32
  • 64-bit vector:
var bv bitvector.Len64
  • 128-bit vector:
var bv bitvector.Ascii
// Or to reinitialize the bit vector
bv = bitvector.NewAscii()

Operations

  • Set ith bit:
bv = bv.Set(i, true)
bv = bv.Set(i, false)
  • Get ith bit:
b := bv.Get(i) // bool
  • Toggle (flip) ith bit:
bv = bv.Toggle(i)
  • Clear bits from index i (included) to index j (excluded):
bv = bv.Clear(i, j)
  • Count the number of bits set to 1:
i := bv.Count() // uint8
  • And operator:
bv := bv1.And(bv2)
  • Or operator:
bv := bv1.Or(bv2)
  • Xor operator:
bv := bv1.Xor(bv2)
  • AndNot operator:
bv := bv1.AndNot(bv2)
  • Push operator (left shift):
bv = bv.Push(2)
  • Pop operator (right shift):
bv = bv.Pop(2)
  • Convert the internal bit vector structure to a string:
s := bv.String() // string
You might also like...
An open source embedding vector similarity search engine powered by Faiss, NMSLIB and Annoy
An open source embedding vector similarity search engine powered by Faiss, NMSLIB and Annoy

Click to take a quick look at our demos! Image search Chatbots Chemical structure search Milvus is an open-source vector database built to power AI ap

Red team tool that emulates the SolarWinds CI compromise attack vector.
Red team tool that emulates the SolarWinds CI compromise attack vector.

SolarSploit Sample malicious program that emulates the SolarWinds attack vector. Listen for processes that use the go compiler Wait for a syscall to o

Generate vector tiles for the entire planet on relatively low spec hardware.
Generate vector tiles for the entire planet on relatively low spec hardware.

Sequentially Generate Planet Mbtiles Sequentially generate and merge an entire planet.mbtiles vector tileset on low memory/power devices for free. com

Go implementation of BLAKE2 (b) cryptographic hash function (optimized for 64-bit platforms).

Go implementation of BLAKE2b collision-resistant cryptographic hash function created by Jean-Philippe Aumasson, Samuel Neves, Zooko Wilcox-O'Hearn, an

Optimized bit-level Reader and Writer for Go.

bitio Package bitio provides an optimized bit-level Reader and Writer for Go. You can use Reader.ReadBits() to read arbitrary number of bits from an i

A little bit of magic for keeping track of the things you have to do.

Be productive. To-do lists are supposed to help you get things done. And I suppose looking through all the stuff you still have to do each time you wa

A Go implementation of the 64-bit xxHash algorithm (XXH64)

xxhash xxhash is a Go implementation of the 64-bit xxHash algorithm, XXH64. This is a high-quality hashing algorithm that is much faster than anything

go/golang: fast bit set Bloom filter

package implements a fast bloom filter with real 'bitset' and JSONMarshal/JSONUnmarshal to store/reload the Bloom filter.

Bit is a modern Git CLI
Bit is a modern Git CLI

bit is an experimental modernized git CLI built on top of git that provides happy defaults and other niceties: command and flag suggestions to help yo

A Free 8-Bit Sprite Generator.  Create 256 variants from a single template .PNG
A Free 8-Bit Sprite Generator. Create 256 variants from a single template .PNG

BitSprite A Free 8-Bit Sprite Generator. What? BitSprite is a program that creates variants of an image across total sprite sheet of the resultant ima

Print debugging, but a little bit nicer

testlog Print debugging, but a little bit nicer. The use case this is primarily designed for is effectively debugging problematic, flaky tests.

urlhunter is a recon tool that allows searching on URLs that are exposed via shortener services such as bit.ly and goo.gl.
urlhunter is a recon tool that allows searching on URLs that are exposed via shortener services such as bit.ly and goo.gl.

a recon tool that allows searching on URLs that are exposed via shortener services

this allows you to get the real link of bit.ly
this allows you to get the real link of bit.ly

check the real url from a url shortener (bit.ly) Also you can use it as an API example with deno const rawResponse = await fetch("https://anti-url-s

Yandex Cloud Logging output for Fluent Bit

Fluent Bit plugin for Yandex Cloud Logging Fluent Bit output for Yandex Cloud Logging. Configuration parameters Key Description group_id (optional) Lo

from others structs a bit easier

structcopier This package is copy from deepcopier of Ulule team. Due to deepcopier hasn't updated for a long time, I created this repo to fix some bug

A modification (and a bit of simplification) of the tracerr package.

Decrr A modification (and a bit of simplification) of the tracerr package. This essentially does pretty much the same, but instead of returning anothe

this allows you to get the real link of without get tracked bit.ly
this allows you to get the real link of without get tracked bit.ly

check the real url from a url shortener (bit.ly) Also you can use it as an API example with deno const rawResponse = await fetch("https://anti-url-s

Image compression codec for 16 bit medical images

MIC - Medical Image Codec This library introduces a lossless medical image compression codec MIC for 16 bit images which provides compression ratio si

other glyph sets for high-dpi 1-bit monochrome

hd1b_other other glyph sets for high-dpi 1-bit monochrome Currently included glyph sets: Hangul (Korean): U+1100..U+11FF, U+3131..U+318E, U+AC00..U+D7

Releases(v1.2)
Owner
Teiva Harsanyi
Software Engineer, Go, Rust, Java | @ReactiveX​/​RxGo | 改善
Teiva Harsanyi
IntSet - Integer based Set based on a bit-vector

IntSet - Integer based Set based on a bit-vector Every integer that is stored will be converted to a bit in a word in which its located. The words are

Jakob Möller 0 Feb 2, 2022
Easily and dynamically generate maps from Go static structures

structomap This package helps you to transform your struct into map easily. It provides a structomap.Serializer interface implemented by the structoma

Daniel Perez 137 Sep 8, 2022
Publish Your GIS Data(Vector Data) to PostGIS and Geoserver

GISManager Publish Your GIS Data(Vector Data) to PostGIS and Geoserver How to install: go get -v github.com/hishamkaram/gismanager Usage: testdata fol

Hisham waleed karam 47 Aug 13, 2022
Rasterx is an SVG 2.0 path compliant rasterizer that can use either the golang vector or a derivative of the freetype anti-aliaser.

rasterx Rasterx is a golang rasterizer that implements path stroking functions capable of SVG 2.0 compliant 'arc' joins and explicit loop closing. Pat

Steven R Wiley 107 Sep 13, 2022
Cairo in Go: vector to SVG, PDF, EPS, raster, HTML Canvas, etc.

Canvas is a common vector drawing target that can output SVG, PDF, EPS, raster images (PNG, JPG, GIF, ...), HTML Canvas through WASM, and OpenGL. It h

Taco de Wolff 1k Sep 26, 2022
Vald. A Highly Scalable Distributed Vector Search Engine

Vald is a highly scalable distributed fast approximate nearest neighbor dense vector search engine.

Vector Data as a Service 976 Sep 20, 2022
Weaviate is a cloud-native, modular, real-time vector search engine

Weaviate is a cloud-native, real-time vector search engine (aka neural search engine or deep search engine). There are modules for specific use cases such as semantic search, plugins to integrate Weaviate in any application of your choice, and a console to visualize your data.

SeMI Technologies 2.8k Sep 22, 2022
Weaviate is a cloud-native, modular, real-time vector search engine

Weaviate is a cloud-native, real-time vector search engine (aka neural search engine or deep search engine). There are modules for specific use cases such as semantic search, plugins to integrate Weaviate in any application of your choice, and a console to visualize your data.

SeMI Technologies 2.8k Sep 21, 2022
GoVector is a vector clock logging library written in Go.

GoVector is a vector clock logging library written in Go. The vector clock algorithm is used to order events in distributed systems in the absence of a centralized clock. GoVector implements the vector clock algorithm and provides feature-rich logging and encoding infrastructure.

Distributed clocks 164 Aug 13, 2022
Publish Your GIS Data(Vector Data) to PostGIS and Geoserver

GISManager Publish Your GIS Data(Vector Data) to PostGIS and Geoserver How to install: go get -v github.com/hishamkaram/gismanager Usage: testdata fol

Hisham waleed karam 48 Sep 26, 2022