GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - cleoold/bitarray: Bit array (or bit set, bit string, boolean vector, ..., whatever) data structure for Lua.

BranchesTags
Open more actions menu

Latest commit

 

History

34 Commits
34 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
.vscode
.vscode
 
 
doc
doc
 
 
example
example
 
 
ext
ext
 
 
test
test
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
_config.yml
_config.yml
 
 
bitarray-1.5-1.rockspec
bitarray-1.5-1.rockspec
 
 
bitarray-scm-1.rockspec
bitarray-scm-1.rockspec
 
 
config.ld
config.ld
 
 

Repository files navigation

LuaRocks dev-build-ci

Bitarray

A simple bit array (or bit set, bit string, boolean vector, ... whatever) data structure for Lua written in pure C.

The data structure Bitarray stores bits (booleans) in an array in a memory-saving manner internally. One can assign value (false or true) to each element as well as extract values from the array.

  • Array bit access using overloaded [] operators, concatenation with .., as well as &, |, ~ for bit operations (5.3+).
  • Object-oriented access. Method chaining is available.
  • Conversion between bitarray and unsigned integers (big-endian).

Install from luarocks

It will install the release version.

luarocks install bitarray

Build the library manually

make all LUA_VERSION=5.3 # or 5.1, 5.2

The generated shared library will reside in out folder. Unfortunately, I understand the difficulty of finding the right install path for libraries for different platforms so it is your responsibility to copy the file there. Typically it can be /usr/local/lib/lua/5.3/.

FreeBSD users will need to use gmake.

Documentation

Requiring ldoc, available by issuing

make doc

It is also available at here.

Basic usage

Array access

local Bitarray = require'bitarray'
local a = Bitarray.new(10)
a[1] = true
for i = 1, #a do print(a[i]) end
-- true false false false false false false false false false

Method chaining

local b = Bitarray.new(10)
b:fill(true):set(1, false):set(#b, false)
print(b)
-- Bitarray[0,1,1,1,1,1,1,1,1,0]

Storing integers

local c1 = Bitarray.new(16):from_uint16(65535)
print(c1)
-- Bitarray[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
local c2 = Bitarray.new(16):from_uint16(4015)
print(c2)
-- Bitarray[0,0,0,0,1,1,1,1,1,0,1,0,1,1,1,1]
local c3 = c1 .. c2
print(c3)
-- Bitarray[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0,1,0,1,1,1,1]
print(c3:at_uint16(1))
-- 65535
print(c3:at_uint16(17))
-- 4015
print(c3:at_uint32(1))
-- 4294905775

License

MIT

About

Bit array (or bit set, bit string, boolean vector, ..., whatever) data structure for Lua.

cleoold.github.io/bitarray/

Topics

bitarraybitsetlua

Resources

Readme
MIT license
Activity

Stars

15 stars

Watchers

1 watching

Forks

4 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.