GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-b4187339ee
sparse.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <grass/linkm.h>
#include <grass/bitmap.h>
Include dependency graph for sparse.c:

Go to the source code of this file.

Macros

#define BM_col_to_byte(x)   ((x) >> 3) /* x / 8 */
 
#define BM_col_to_bit(x)   ((x) & 7) /* x % 8 */
 

Functions

struct BMBM_create_sparse (int x, int y)
 Create a sparse bitmap of dimension 'x'/'y'. More...
 
int BM_destroy_sparse (struct BM *map)
 Destroy sparse bitmap and free all associated memory. More...
 
int BM_set_sparse (struct BM *map, int x, int y, int val)
 Set sparse bitmap value to 'val' at location 'x'/'y'. More...
 
int BM_get_sparse (struct BM *map, int x, int y)
 Returns sparse bitmap value at location 'x'/'y'. More...
 
size_t BM_get_map_size_sparse (struct BM *map)
 Returns size of sparse bitmap in bytes. More...
 
int BM_dump_map_sparse (struct BM *map)
 Debugging code to dump out structure of links. More...
 
int BM_dump_map_row_sparse (struct BM *map, int y)
 Debugging code to dump out structure of links for single row. More...
 
int BM_file_write_sparse (FILE *fp, struct BM *map)
 Write sparse bitmap matrix out to disk file 'fp'. NOTE: 'fp' must already be opened and later closed by user. More...
 

Macro Definition Documentation

◆ BM_col_to_bit

#define BM_col_to_bit (   x)    ((x) & 7) /* x % 8 */

Definition at line 26 of file sparse.c.

◆ BM_col_to_byte

#define BM_col_to_byte (   x)    ((x) >> 3) /* x / 8 */

Definition at line 25 of file sparse.c.

Function Documentation

◆ BM_create_sparse()

struct BM* BM_create_sparse ( int  x,
int  y 
)

Create a sparse bitmap of dimension 'x'/'y'.

Returns bitmap structure or NULL on error

Parameters
x
y
Returns
struct BM

Definition at line 42 of file sparse.c.

References BM::bytes, BM::cols, count, BM::data, free(), link_init(), link_new(), link_set_chunk_size(), malloc(), NULL, BM::rows, BM::sparse, BM::token, BMlink::val, and x.

Referenced by main().

◆ BM_destroy_sparse()

int BM_destroy_sparse ( struct BM map)

Destroy sparse bitmap and free all associated memory.

Returns 0

Parameters
map
Returns
int

Definition at line 88 of file sparse.c.

Referenced by BM_destroy().

◆ BM_dump_map_row_sparse()

int BM_dump_map_row_sparse ( struct BM map,
int  y 
)

Debugging code to dump out structure of links for single row.

Returns 0

Parameters
map
y
Returns
int

Definition at line 323 of file sparse.c.

References BMlink::count, BM::data, BMlink::next, NULL, and BMlink::val.

◆ BM_dump_map_sparse()

int BM_dump_map_sparse ( struct BM map)

Debugging code to dump out structure of links.

Returns 0

Parameters
map
Returns
int

Definition at line 294 of file sparse.c.

References BMlink::count, BM::data, BMlink::next, NULL, BM::rows, and BMlink::val.

◆ BM_file_write_sparse()

int BM_file_write_sparse ( FILE *  fp,
struct BM map 
)

Write sparse bitmap matrix out to disk file 'fp'. NOTE: 'fp' must already be opened and later closed by user.

Returns 0 on success or -1 on error

Parameters
fp
map
Returns
int

Definition at line 354 of file sparse.c.

◆ BM_get_map_size_sparse()

size_t BM_get_map_size_sparse ( struct BM map)

Returns size of sparse bitmap in bytes.

Parameters
map
Returns
int

Definition at line 265 of file sparse.c.

References BM::data, BMlink::next, NULL, and BM::rows.

Referenced by BM_get_map_size().

◆ BM_get_sparse()

int BM_get_sparse ( struct BM map,
int  x,
int  y 
)

Returns sparse bitmap value at location 'x'/'y'.

Returns value or -1 on error

Parameters
map
x
y
Returns
int

Definition at line 240 of file sparse.c.

References BMlink::count, cur_x, BM::data, BMlink::next, NULL, BMlink::val, and x.

Referenced by BM_get().

◆ BM_set_sparse()

int BM_set_sparse ( struct BM map,
int  x,
int  y,
int  val 
)

Set sparse bitmap value to 'val' at location 'x'/'y'.

Returns 0

Parameters
map
x
y
val
Returns
int

Definition at line 125 of file sparse.c.

References BMlink::count, cur_x, BM::data, link_dispose(), link_new(), BMlink::next, NULL, BM::token, BMlink::val, VOID_T, and x.

Referenced by BM_set().