Module bitfield stdlib

bitfield
Version:
0.3.3
License:
MIT
Dependencies from vmod:
0
Imports:
0
Imported by:
0
Repository:
OS-specific
Show selected OS-specific symbols.
Backend-specific
Show selected Backend-specific symbols.

Dependencies defined in v.mod

This section is empty.

Imports

This section is empty.

Imported by

This section is empty.

Overview

bitfield is a module for manipulating arrays of bits, i.e. series of zeroes and ones spread across an array of storage units (unsigned 32-bit integers).

BitField Structure

Bit arrays are stored in data structures called 'BitField'. The structure is 'opaque', i.e. its internals are not available to the end user. This module provides API (functions and methods) for accessing and modifying bit arrays.

Aliases

This section is empty.

Constants

This section is empty.

Sum types

This section is empty.

Functions

#fn bf_and

fn bf_and(input1 BitField, input2 BitField) BitField

bf_and performs logical AND operation on every pair of bits from 'input1' and 'input2' and returns the result as a new array. If inputs differ in size, the tail of the longer one is ignored.

#fn bf_not

fn bf_not(input BitField) BitField

bf_not toggles all bits in a bit array and returns the result as a new array.

#fn bf_or

fn bf_or(input1 BitField, input2 BitField) BitField

bf_or performs logical OR operation on every pair of bits from 'input1' and 'input2' and returns the result as a new array. If inputs differ in size, the tail of the longer one is ignored.

#fn bf_xor

fn bf_xor(input1 BitField, input2 BitField) BitField

bf_xor perform logical XOR operation on every pair of bits from 'input1' and 'input2' and returns the result as a new array. If inputs differ in size, the tail of the longer one is ignored.

#fn from_bytes

fn from_bytes(input []u8) BitField

from_bytes converts a byte array into a bitfield.

[0x0F, 0x01] => 0000 1111 0000 0001

#fn from_bytes_lowest_bits_first

fn from_bytes_lowest_bits_first(input []u8) BitField

from_bytes_lowest_bits_first converts a byte array into a bitfield [0x0F, 0x01] => 1111 0000 1000 0000

#fn from_str

fn from_str(input string) BitField

from_str converts a string of characters ('0' and '1') to a bit array. Any character different from '0' is treated as '1'.

#fn hamming

inline
fn hamming(input1 BitField, input2 BitField) int

hamming computes the Hamming distance between two bit arrays.

#fn join

fn join(input1 BitField, input2 BitField) BitField

join concatenates two bit arrays and return the result as a new array.

#fn new

fn new(size int) BitField

new creates an empty bit array of capable of storing 'size' bits.

Structs

#struct BitField

pub struct BitField {
mut:
	size int
	// field *u32
	field []u32
}

#fn (BitField) str

fn (input BitField) str() string

str converts the bit array to a string of characters ('0' and '1') and return the string

#fn (&BitField) free

unsafe
fn (instance &BitField) free()

frees the memory allocated for the bitfield instance

#fn (BitField) get_bit

inline
fn (instance BitField) get_bit(bitnr int) int

get_bit returns the value (0 or 1) of bit number 'bit_nr' (count from 0).

#fn (&BitField) set_bit

inline
fn (mut instance &BitField) set_bit(bitnr int)

set_bit sets bit number 'bit_nr' to 1 (count from 0).

#fn (&BitField) clear_bit

inline
fn (mut instance &BitField) clear_bit(bitnr int)

clear_bit clears (sets to zero) bit number 'bit_nr' (count from 0).

#fn (BitField) extract

fn (instance BitField) extract(start int, len int) u64

extract returns the value converted from a slice of bit numbers from 'start' by the length of 'len'.

0101 (1, 2) => 0b10

#fn (&BitField) insert[T]

fn (mut instance &BitField) insert(start int, len int, _value T)

insert sets bit numbers from 'start' to 'len' length with the value converted from the number 'value'.

0000 (1, 2, 0b10) => 0100

#fn (BitField) extract_lowest_bits_first

fn (instance BitField) extract_lowest_bits_first(start int, len int) u64

extract returns the value converted from a slice of bit numbers from 'start' by the length of 'len'.

0101 (1, 2) => 0b01

#fn (&BitField) insert_lowest_bits_first[T]

fn (mut instance &BitField) insert_lowest_bits_first(start int, len int, _value T)

insert sets bit numbers from 'start' to 'len' length with the value converted from the number 'value'.

0000 (1, 2, 0b10) => 0010

#fn (&BitField) set_all

fn (mut instance &BitField) set_all()

set_all sets all bits in the array to 1.

#fn (&BitField) clear_all

fn (mut instance &BitField) clear_all()

clear_all clears (sets to zero) all bits in the array.

#fn (&BitField) toggle_bit

inline
fn (mut instance &BitField) toggle_bit(bitnr int)

toggle_bit changes the value (from 0 to 1 or from 1 to 0) of bit number 'bit_nr'.

#fn (BitField) get_size

inline
fn (instance BitField) get_size() int

get_size returns the number of bits the array can hold.

#fn (BitField) clone

fn (instance BitField) clone() BitField

clone creates a copy of a bit array.

#fn (BitField) operator==

fn (a BitField) == (b BitField) bool

== compares 2 bitfields, and returns true when they are equal

#fn (BitField) pop_count

fn (instance BitField) pop_count() int

pop_count returns the number of set bits (ones) in the array.

#fn (BitField) pos

fn (haystack BitField) pos(needle BitField) int

pos checks if the array contains a sub-array 'needle' and returns its position if it does, -1 if it does not, and -2 on error.

#fn (BitField) slice

fn (input BitField) slice(_start int, _end int) BitField

slice returns a sub-array of bits between 'start_bit_nr' (included) and 'end_bit_nr' (excluded).

#fn (BitField) reverse

fn (instance BitField) reverse() BitField

reverse reverses the order of bits in the array (swap the first with the last, the second with the last but one and so on).

#fn (&BitField) resize

fn (mut instance &BitField) resize(new_size int)

resize changes the size of the bit array to 'new_size'.

#fn (BitField) rotate

fn (instance BitField) rotate(offset int) BitField

rotate circular-shifts the bits by 'offset' positions (move 'offset' bit to 0, 'offset+1' bit to 1, and so on).

#fn (&BitField) clear_tail

inline
fn (mut instance &BitField) clear_tail()

Internal functions clear_tail clears the extra bits that are not part of the bitfield, but yet are allocated

Interfaces

This section is empty.

Enums

This section is empty.