Freeciv-3.1
Loading...
Searching...
No Matches
Functions
bitvector.c File Reference
#include "fc_prehdrs.h"
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "fciconv.h"
#include "fcintl.h"
#include "mem.h"
#include "rand.h"
#include "string_vector.h"
#include "bitvector.h"

Go to the source code of this file.

Functions

void dbv_init (struct dbv *pdbv, int bits)
 
void dbv_resize (struct dbv *pdbv, int bits)
 
void dbv_free (struct dbv *pdbv)
 
int dbv_bits (struct dbv *pdbv)
 
bool dbv_isset (const struct dbv *pdbv, int bit)
 
bool dbv_isset_any (const struct dbv *pdbv)
 
void dbv_set (struct dbv *pdbv, int bit)
 
void dbv_set_all (struct dbv *pdbv)
 
void dbv_clr (struct dbv *pdbv, int bit)
 
void dbv_clr_all (struct dbv *pdbv)
 
bool dbv_are_equal (const struct dbv *pdbv1, const struct dbv *pdbv2)
 
bool bv_match_dbv (const struct dbv *match, const unsigned char *src)
 
void dbv_copy (struct dbv *dest, const struct dbv *src)
 
void dbv_to_bv (unsigned char *dest, const struct dbv *src)
 
void bv_to_dbv (struct dbv *dest, const unsigned char *src)
 
void dbv_debug (struct dbv *pdbv)
 
bool bv_check_mask (const unsigned char *vec1, const unsigned char *vec2, size_t size1, size_t size2)
 
bool bv_are_equal (const unsigned char *vec1, const unsigned char *vec2, size_t size1, size_t size2)
 
void bv_set_all_from (unsigned char *vec_to, const unsigned char *vec_from, size_t size_to, size_t size_from)
 
void bv_clr_all_from (unsigned char *vec_to, const unsigned char *vec_from, size_t size_to, size_t size_from)
 

Function Documentation

◆ bv_are_equal()

bool bv_are_equal ( const unsigned char *  vec1,
const unsigned char *  vec2,
size_t  size1,
size_t  size2 
)

Compare elements of two bitvectors. Both vectors are expected to have same number of elements, i.e. , size1 must be equal to size2.

Definition at line 302 of file bitvector.c.

Referenced by dbv_are_equal().

◆ bv_check_mask()

bool bv_check_mask ( const unsigned char *  vec1,
const unsigned char *  vec2,
size_t  size1,
size_t  size2 
)

Return whether two vectors: vec1 and vec2 have common bits. I.e. (vec1 & vec2) != 0.

Don't call this function directly, use BV_CHECK_MASK macro instead. Don't call this function with two different bitvectors.

Definition at line 280 of file bitvector.c.

Referenced by dbv_isset_any().

◆ bv_clr_all_from()

void bv_clr_all_from ( unsigned char *  vec_to,
const unsigned char *  vec_from,
size_t  size_to,
size_t  size_from 
)

Clear everything that is true in vec_from in vec_to. Stuff that already is false in vec_to aren't touched.

Both vectors are expected to have same number of elements, i.e. , size1 must be equal to size2.

Don't call this function directly, use BV_CLR_ALL_FROM macro instead.

Definition at line 351 of file bitvector.c.

◆ bv_match_dbv()

bool bv_match_dbv ( const struct dbv match,
const unsigned char *  src 
)

Is content of static bitvector same as that of dynamic one. Comparison size is taken from the dynamic one.

Definition at line 205 of file bitvector.c.

◆ bv_set_all_from()

void bv_set_all_from ( unsigned char *  vec_to,
const unsigned char *  vec_from,
size_t  size_to,
size_t  size_from 
)

Set everything that is true in vec_from in vec_to. Stuff that already is true in vec_to aren't touched. (Bitwise inclusive OR assignment)

Both vectors are expected to have same number of elements, i.e. , size1 must be equal to size2.

Don't call this function directly, use BV_SET_ALL_FROM macro instead.

Definition at line 329 of file bitvector.c.

◆ bv_to_dbv()

void bv_to_dbv ( struct dbv dest,
const unsigned char *  src 
)

Copy static bit vector content to dynamic bitvector. Static vector is assumed to be at least same size as the dynamic one.

Definition at line 244 of file bitvector.c.

◆ dbv_are_equal()

bool dbv_are_equal ( const struct dbv pdbv1,
const struct dbv pdbv2 
)

Check if the two dynamic bitvectors are equal.

Definition at line 190 of file bitvector.c.

◆ dbv_bits()

int dbv_bits ( struct dbv pdbv)

Returns the number of bits defined in a dynamic bitvector.

Definition at line 108 of file bitvector.c.

◆ dbv_clr()

void dbv_clr ( struct dbv pdbv,
int  bit 
)

Clear the bit given by 'bit'.

Definition at line 167 of file bitvector.c.

Referenced by api_edit_tile_hide(), handle_tile_info(), and map_clear_known().

◆ dbv_clr_all()

void dbv_clr_all ( struct dbv pdbv)

Clear all bits.

Definition at line 179 of file bitvector.c.

Referenced by dbv_init(), dbv_resize(), make_rivers(), sg_load_map_known(), and sg_load_map_known().

◆ dbv_copy()

void dbv_copy ( struct dbv dest,
const struct dbv src 
)

Copy dynamic bit vector content from another.

Definition at line 222 of file bitvector.c.

◆ dbv_debug()

void dbv_debug ( struct dbv pdbv)

Debug a dynamic bitvector.

Definition at line 252 of file bitvector.c.

◆ dbv_free()

void dbv_free ( struct dbv pdbv)

Destroy a dynamic bitvector.

Definition at line 95 of file bitvector.c.

Referenced by check_native_area(), is_city_channel_tile(), make_rivers(), player_destroy(), player_map_free(), and remove_city().

◆ dbv_init()

void dbv_init ( struct dbv pdbv,
int  bits 
)

Initialize a dynamic bitvector of size 'bits'. 'bits' must be greater than 0 and lower than the maximal size given by MAX_DBV_LENGTH. The bitvector is set to all clear.

Definition at line 50 of file bitvector.c.

Referenced by check_native_area(), dbv_resize(), is_city_channel_tile(), make_rivers(), player_map_init(), and remove_city().

◆ dbv_isset()

bool dbv_isset ( const struct dbv pdbv,
int  bit 
)

◆ dbv_isset_any()

bool dbv_isset_any ( const struct dbv pdbv)

Test if any bit is set.

Definition at line 132 of file bitvector.c.

◆ dbv_resize()

void dbv_resize ( struct dbv pdbv,
int  bits 
)

Resize a dynamic bitvector. Create it if needed.

Definition at line 71 of file bitvector.c.

Referenced by client_player_maps_reset(), and dbv_copy().

◆ dbv_set()

void dbv_set ( struct dbv pdbv,
int  bit 
)

◆ dbv_set_all()

void dbv_set_all ( struct dbv pdbv)

Set all bits.

Definition at line 156 of file bitvector.c.

◆ dbv_to_bv()

void dbv_to_bv ( unsigned char *  dest,
const struct dbv src 
)

Copy dynamic bit vector content to static bitvector. Static vector is assumed to be at least same size as the dynamic one.

Definition at line 235 of file bitvector.c.