项目作者: KarpelesLab

项目描述 :
Bitmap manipulation in Go
高级语言: Go
项目地址: git://github.com/KarpelesLab/bitmap.git
创建时间: 2019-12-29T14:57:05Z
项目社区:https://github.com/KarpelesLab/bitmap

开源协议:

下载


Build Status
GoDoc
Coverage Status

Bitmap

Simple bitmaps in Go.

Provides the following methods on bitmap objects:

  • Get(bit int)
  • Set(bit int, value bool)
  • Toggle(bit)
  • GetAtomic(bit int)
  • SetAtomic(bit int, value bool)
  • ToggleAtomic(bit int)

Example

  1. m := bitmap.New(127)
  2. m.Set(42, true)
  3. if m.Get(42) {
  4. // OK
  5. }

Why?

There are already a few bitmap implementations in Go available out there, however they have some shortfalls and/or are too complex for what a bitmap should do.

  • boljen’s go-bitmap has separate implementations for Bitmap/Concurrent/Threadsafe, and complexifies a lot what should be very simple.
  • ShawnMilo’s bitmap has a nice feel but lacks atomic methods and adds string methods using json/gzip/base64 (?)
  • Roaring Bitmaps are simply too complex for what I need bitmaps for. You should however definitely use that if you store more than 200k bits or so in total.