Simple Bitmap v1.1.0 SimpleBitmap View Source
Simple Bitmap to use the big integer to store (and extend) the bitmap.
Example:
iex> b = SimpleBitmap.new() %SimpleBitmap{data: 0} iex> b = SimpleBitmap.set(b, 5) %SimpleBitmap{data: 32} iex> b = SimpleBitmap.set(b, 10) %SimpleBitmap{data: 1056} iex> b = SimpleBitmap.set(b, 38) %SimpleBitmap{data: 274877908000} iex> b = SimpleBitmap.set(b, 179) %SimpleBitmap{data: 766247770432944429179173513575154591809369835969709088} iex> SimpleBitmap.msb(b) 179 iex> SimpleBitmap.msb(b, 10) [179, 38, 10, 5, 0, 0, 0, 0, 0, 0]
Link to this section Summary
Functions
Load a bitmap from a file
Get the index of the most significant bit
Get a list of most significant bits
Initialize a bitmap
Save the bitmap into file iex> b = SimpleBitmap.new(1024) %SimpleBitmap{data: 1024} iex> b = SimpleBitmap.set(b, 9) %SimpleBitmap{data: 1536} iex> SimpleBitmap.save(b, "/tmp/simple_bitmap") :ok
Set the bit to 1 for given index
Check if a bit is set to 1 for given index
Set the bit to 0 for given index
Link to this section Types
t()
View Source
t() :: %SimpleBitmap{data: term()}
t() :: %SimpleBitmap{data: term()}
Link to this section Functions
load(filename) View Source
Load a bitmap from a file
iex> b = SimpleBitmap.new(1024) %SimpleBitmap{data: 1024} iex> b = SimpleBitmap.set(b, 9) %SimpleBitmap{data: 1536} iex> b = SimpleBitmap.set(b, 225) %SimpleBitmap{
data: 53919893334301279589334030174039261347274288845081144962207220499968
} iex> SimpleBitmap.save(b, "/tmp/simple_bitmap") iex> SimpleBitmap.load("/tmp/simple_bitmap") %SimpleBitmap{
data: 53919893334301279589334030174039261347274288845081144962207220499968
}
msb(bitmap)
View Source
msb(t()) :: non_neg_integer()
msb(t()) :: non_neg_integer()
Get the index of the most significant bit.
iex> b = SimpleBitmap.new() iex> b = SimpleBitmap.set(b, 301) iex> b = SimpleBitmap.set(b, 4) iex> b = SimpleBitmap.set(b, 252) iex> SimpleBitmap.msb(b) 301
msb(bitmap, length)
View Source
msb(t(), non_neg_integer()) :: [non_neg_integer()]
msb(t(), non_neg_integer()) :: [non_neg_integer()]
Get a list of most significant bits.
iex> b = SimpleBitmap.new() iex> b = SimpleBitmap.set(b, 1) iex> b = SimpleBitmap.set(b, 4) iex> b = SimpleBitmap.set(b, 9) iex> b = SimpleBitmap.set(b, 33) iex> b = SimpleBitmap.set(b, 1753421) iex> b = SimpleBitmap.set(b, 9326887) iex> b = SimpleBitmap.unset(b, 32) iex> b = SimpleBitmap.unset(b, 9) iex> SimpleBitmap.msb(b, 10) [9326887, 1753421, 33, 4, 1, 0, 0, 0, 0, 0]
new(data \\ 0)
View Source
new(non_neg_integer()) :: t()
new(non_neg_integer()) :: t()
Initialize a bitmap.
iex> SimpleBitmap.new() %SimpleBitmap{data: 0} iex> SimpleBitmap.new(1024) %SimpleBitmap{data: 1024}
save(bitmap, filename) View Source
Save the bitmap into file iex> b = SimpleBitmap.new(1024) %SimpleBitmap{data: 1024} iex> b = SimpleBitmap.set(b, 9) %SimpleBitmap{data: 1536} iex> SimpleBitmap.save(b, "/tmp/simple_bitmap") :ok
set(bitmap, index)
View Source
set(t(), non_neg_integer()) :: t()
set(t(), non_neg_integer()) :: t()
Set the bit to 1 for given index.
iex> b = SimpleBitmap.new() iex> SimpleBitmap.set(b, 3) %SimpleBitmap{data: 8}
set?(bitmap, index)
View Source
set?(t(), non_neg_integer()) :: boolean()
set?(t(), non_neg_integer()) :: boolean()
Check if a bit is set to 1 for given index.
iex> b = SimpleBitmap.new() iex> b = SimpleBitmap.set(b, 15) iex> b = SimpleBitmap.set(b, 16) iex> SimpleBitmap.set?(b, 15) true
unset(bitmap, index)
View Source
unset(t(), non_neg_integer()) :: t()
unset(t(), non_neg_integer()) :: t()
Set the bit to 0 for given index.
iex> b = SimpleBitmap.new() iex> b = SimpleBitmap.set(b, 2) iex> b = SimpleBitmap.set(b, 8) iex> SimpleBitmap.unset(b, 8) %SimpleBitmap{data: 4}