Current section
Files
Jump to
Current section
Files
src/bitsandbobs.erl
-module(bitsandbobs).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([is_atleast_x_bits/2, split_every_x_bits/2, bit_size/1, bit_size_x/2, map/3, zip/3, pad/2, bits_required_to_represent_x_bits/1]).
-file("C:\\Users\\bradl\\Desktop\\bitsandbobs\\src\\bitsandbobs.gleam", 22).
-spec is_atleast_x_bits(bitstring(), integer()) -> boolean().
is_atleast_x_bits(Bitarray, Mininum) ->
case Bitarray of
<<_:Mininum, _/bitstring>> ->
true;
_ ->
false
end.
-file("C:\\Users\\bradl\\Desktop\\bitsandbobs\\src\\bitsandbobs.gleam", 8).
-spec split_every_x_bits(bitstring(), integer()) -> list(bitstring()).
split_every_x_bits(Bitarray, Every) ->
case Bitarray of
<<Chunk:Every/bitstring, Rest/bitstring>> ->
lists:append([Chunk], split_every_x_bits(Rest, Every));
Remainder ->
case begin
_pipe = Remainder,
is_atleast_x_bits(_pipe, 1)
end of
false ->
[];
true ->
[Remainder]
end
end.
-file("C:\\Users\\bradl\\Desktop\\bitsandbobs\\src\\bitsandbobs.gleam", 44).
-spec bit_size_recursive(bitstring(), integer()) -> integer().
bit_size_recursive(Bitarray, Read_size) ->
case Bitarray of
<<_:Read_size, Rest/bitstring>> ->
Read_size + bit_size_recursive(Rest, Read_size);
_ ->
case Read_size div 2 of
0 ->
0;
New_read_size ->
bit_size_recursive(Bitarray, New_read_size)
end
end.
-file("C:\\Users\\bradl\\Desktop\\bitsandbobs\\src\\bitsandbobs.gleam", 31).
-spec bit_size(bitstring()) -> integer().
bit_size(Bitarray) ->
bit_size_recursive(Bitarray, 8).
-file("C:\\Users\\bradl\\Desktop\\bitsandbobs\\src\\bitsandbobs.gleam", 36).
-spec bit_size_x(bitstring(), integer()) -> integer().
bit_size_x(Bitarray, Starting_size) ->
case Starting_size of
S when S < 1 ->
erlang:error(#{gleam_error => panic,
message => <<"Invalid starting size, must be atleast 1"/utf8>>,
module => <<"bitsandbobs"/utf8>>,
function => <<"bit_size_x"/utf8>>,
line => 38});
_ ->
bit_size_recursive(Bitarray, Starting_size)
end.
-file("C:\\Users\\bradl\\Desktop\\bitsandbobs\\src\\bitsandbobs.gleam", 57).
-spec map(bitstring(), integer(), fun((bitstring()) -> bitstring())) -> bitstring().
map(Bitarray, Every, F) ->
_pipe = split_every_x_bits(Bitarray, Every),
_pipe@1 = gleam@list:map(_pipe, F),
gleam_stdlib:bit_array_concat(_pipe@1).
-file("C:\\Users\\bradl\\Desktop\\bitsandbobs\\src\\bitsandbobs.gleam", 68).
-spec zip(bitstring(), bitstring(), integer()) -> list({bitstring(),
bitstring()}).
zip(First, Second, Every) ->
gleam@list:zip(
split_every_x_bits(First, Every),
split_every_x_bits(Second, Every)
).
-file("C:\\Users\\bradl\\Desktop\\bitsandbobs\\src\\bitsandbobs.gleam", 77).
-spec pad(bitstring(), integer()) -> bitstring().
pad(Bitarray, Amount_of_padding) ->
gleam@bit_array:append(
<<0:(lists:max([(Amount_of_padding), 0]))>>,
Bitarray
).
-file("C:\\Users\\bradl\\Desktop\\bitsandbobs\\src\\bitsandbobs.gleam", 82).
-spec bits_required_to_represent_x_bits(integer()) -> integer().
bits_required_to_represent_x_bits(Int) ->
Int.