preciz

preciz

Abit - functions to work with :atomics as a bit array (?)

I have extracted this small package from one of my hobby projects.
If anybody is comfortable with bitmasks or Elxir.Bitwise it would be cool to receive some feedback on this.

I’m not sure about a few naming and the complexity of the code when I’m setting a bit with Abit.set_bit/3.

GitHub: GitHub - preciz/abit: Use :atomics as a bit array or as an array of N-bit counters · GitHub
Hexdocs: abit v0.4.0 — Documentation

It’s main use case is if you use an :atomics array as a bit array.

Most Liked

preciz

preciz

I have added a module Abit.Counter.
This is similar to Erlang :counters but it allows you to use counters with smaller than 64 bit sizes:

bits | unsigned value range | signed value range
2      0..3                   -2..1
4      0..15                  -8..7
8      0..255                 -128..127
16     0..65535               -32768..32767
32     0..4294967295          -2147483648..2147483647

So for example if you only need max value 255 (8 bits) unsigned, you can have atomics_size * 8 counters instead of just atomics_size.

Here is the short summary of the API of Abit.Counter module:

Abit.Counter

  • Abit.Counter.new/2 - Create a new array of counters. Returns %Abit.Counter{} struct.
  • Abit.Counter.get/2 - Returns the value of counter at the given index.
  • Abit.Counter.put/3 - Puts the value into counter at the given index.
  • Abit.Counter.add/3 - Adds the increment to counter at the given index.

Where Next?

Popular in Announcing Top

josevalim
EDIT: since Ecto 3.0 final version is out, this post was amended to use the final versions in the instructions below. Hi everyone, We a...
New
devonestes
Introducing assertions, the library that helps you write really great test assertions! GitHub: GitHub - devonestes/assertions: Helpful a...
New
RobertDober
Earmark is a pure-Elixir Markdown converter. It is intended to be used as a library (just call Earmark.as_html), but can also be used as...
239 12888 134
New
tmbb
PhoenixWS - Websockets over Phoenix Channels Source code on Github here: GitHub - tmbb/phoenix_ws: Websockets implemented over Phoenix Ch...
New
nikokozak
Hello all, I’ve been working on Svonix - a library for quickly integrating Svelte components into Phoenix views. It’s a much-needed succ...
New
trisolaran
Hi! :waving_hand: I would like to present LiveSelect, a little library that I wrote to easily add a dynamic selection input to your LV f...
198 11220 107
New
zachdaniel
Ash Framework What is Ash? Ash Framework is a declarative, resource-oriented application development framework for Elixir. A resource can...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement