bitmap v1.0.1 Bitmap.Integer
Bitmap behaviour implementation using arbitrarily sized integers.
Summary
Types
A typed map which holds the integer bitmap as defined by the module struct
Functions
Returns the bit value at index
in the bitmap
Inspects the bitmap and returns the string representation of the bitmap
Creates and returns a bitmap of size corresponding to the argument
passed
Sets the bit at index
in the bitmap and returns the new bitmap
Returns a boolean representing whether the bit at position index
is set or not
Set all bits in the bitmap and returns a new bitmap
Returns the string representation of the bitmap
Toggles the bit at index
in the bitmap and returns the new bitmap
i.e. it sets the bit to 1 if it was 0 or sets the bit to 0 if it was 1
Toggles all bits in the bitmap and returns a new bitmap
Unsets the bit at index
in the bitmap and returns the new bitmap
Returns a boolean representing whether the bit at position index
is unset or not
Unsets all bits in the bitmap and returns a new bitmap
Types
Functions
Returns the bit value at index
in the bitmap
Examples
iex> bm = Bitmap.Integer.new(5)
iex> Bitmap.Integer.at(bm, 2)
0
iex> bm = Bitmap.Integer.set(bm, 2)
iex> Bitmap.Integer.at(bm, 2)
1
Inspects the bitmap and returns the string representation of the bitmap
Note: This can be very long for huge bitmaps.
Creates and returns a bitmap of size corresponding to the argument
passed.
If argument
is
- integer, size of bitmap is equal to the
argument
- range, size of bitmap is equal to the length of
argument
- list, size of bitmap is equal to the length of
argument
Note: All bits are set to 0 by default
Examples
iex> Bitmap.Integer.new(400)
%Bitmap.Integer{data: 0, size: 400}
iex> Bitmap.Integer.new([1,2,3,4,5])
%Bitmap.Integer{data: 0, size: 5}
iex> Bitmap.Integer.new(1..25)
%Bitmap.Integer{data: 0, size: 25}
Sets the bit at index
in the bitmap and returns the new bitmap
Index can also have a value :all
in which case all bits
will be set like in set_all
Examples
iex> Bitmap.Integer.set(Bitmap.Integer.new(5), 3)
%Bitmap.Integer{data: 8, size: 5}
iex> Bitmap.Integer.set(Bitmap.Integer.new(1..10), 2)
%Bitmap.Integer{data: 4, size: 10}
Returns a boolean representing whether the bit at position index
is set or not
Examples
iex> bm = Bitmap.Integer.new(5) |> Bitmap.Integer.set(1) |> Bitmap.Integer.set(3)
iex> Bitmap.Integer.set?(bm, 1)
true
iex> Bitmap.Integer.set?(bm, 4)
false
Set all bits in the bitmap and returns a new bitmap
Examples
iex> Bitmap.Integer.set_all(Bitmap.Integer.new(10))
%Bitmap.Integer{data: 1023, size: 10}
iex> Bitmap.Integer.set_all(Bitmap.Integer.new(100))
%Bitmap.Integer{data: 1267650600228229401496703205375, size: 100}
Returns the string representation of the bitmap
Note: This can be very long for huge bitmaps.
Toggles the bit at index
in the bitmap and returns the new bitmap
i.e. it sets the bit to 1 if it was 0 or sets the bit to 0 if it was 1
Index can also have a value :all
in which case all bits will be toggled
like in toggle_all
Examples
iex> bm = Bitmap.Integer.new(10) |> Bitmap.Integer.set(4) |> Bitmap.Integer.set(8)
iex> Bitmap.Integer.toggle(bm, 3)
%Bitmap.Integer{data: 280, size: 10}
iex> Bitmap.Integer.toggle(bm, 6)
%Bitmap.Integer{data: 336, size: 10}
Toggles all bits in the bitmap and returns a new bitmap
Examples
iex> bm = Bitmap.Integer.new(10) |> Bitmap.Integer.set(4) |> Bitmap.Integer.set(8)
iex> Bitmap.Integer.toggle_all(bm)
%Bitmap.Integer{data: -273, size: 10}
Unsets the bit at index
in the bitmap and returns the new bitmap
Index can also have a value :all
in which case all bits
will be unset like in unset_all
Examples
iex> bm = Bitmap.Integer.new(10) |> Bitmap.Integer.set(4) |> Bitmap.Integer.set(8)
iex> Bitmap.Integer.unset(bm, 4)
%Bitmap.Integer{data: 256, size: 10}
iex> Bitmap.Integer.unset(bm, 8)
%Bitmap.Integer{data: 16, size: 10}
Returns a boolean representing whether the bit at position index
is unset or not
Examples
iex> bm = Bitmap.Integer.new(5) |> Bitmap.Integer.set(1) |> Bitmap.Integer.set(3)
iex> Bitmap.Integer.unset?(bm, 1)
false
iex> Bitmap.Integer.unset?(bm, 4)
true