Volksdata 1.0b7
RDF library
Loading...
Searching...
No Matches
Buffer module
Collaboration diagram for Buffer module:

Data Structures

struct  VOLK_Buffer
 General-purpose data buffer. More...
struct  VOLK_BufferTriple
 Triple of byte buffers. More...

Macros

#define NULL_KEY   0
 "NULL" key, a value that is never user-provided.
#define BUF_DUMMY   VOLK_buffer_new (NULL, 0)
 Dummy buffer to be used with VOLK_buffer_init.
#define BTRP_DUMMY   VOLK_btriple_new (BUF_DUMMY, BUF_DUMMY, BUF_DUMMY)
 Dummy buffer triple.

Enumerations

enum  VOLK_TriplePos { TRP_POS_S = 0 , TRP_POS_P = 1 , TRP_POS_O = 2 }
 Triple position of s, p, o. More...
enum  VOLK_BufferFlag { VOLK_BUF_BORROWED = 1<<0 }
 Buffer flags, stored in buffer structure. More...

Functions

VOLK_rc VOLK_buffer_init (VOLK_Buffer *buf, const size_t size, const unsigned char *data)
 Initialize or reuse a buffer handle.
VOLK_BufferVOLK_buffer_new (const unsigned char *data, const size_t size)
 Create a new buffer and optionally populate it with data.
VOLK_BufferVOLK_buffer_new_borrowed (unsigned char *data, const size_t size)
 Create a borrowed buffer (memory view).
void VOLK_buffer_done (VOLK_Buffer *buf)
 Free the content of a buffer.
void VOLK_buffer_free (VOLK_Buffer *buf)
 Free a buffer.
VOLK_Key VOLK_buffer_hash (const VOLK_Buffer *buf)
 Hash a buffer.
void VOLK_buffer_print (const VOLK_Buffer *buf)
 Print a byte string of a given length in a human-readable format.
char * VOLK_buffer_as_str (const VOLK_Buffer *buf)
 Format a buffer into anb ASCII string.
int VOLK_buffer_cmp (const VOLK_Buffer *buf1, const VOLK_Buffer *buf2)
 Compare two buffers.
bool VOLK_buffer_eq (const VOLK_Buffer *buf1, const VOLK_Buffer *buf2)
 Return whether two buffers are equal.
VOLK_BufferTripleVOLK_btriple_new (VOLK_Buffer *s, VOLK_Buffer *p, VOLK_Buffer *o)
 Create a new buffer triple.
VOLK_rc VOLK_btriple_init (VOLK_BufferTriple *sspo, VOLK_Buffer *s, VOLK_Buffer *p, VOLK_Buffer *o)
 Initialize internal term pointers in a heap-allocated buffer triple.
void VOLK_btriple_done (VOLK_BufferTriple *sspo)
 Free the internal pointers of a buffer triple.
void VOLK_btriple_free (VOLK_BufferTriple *sspo)
 Free a buffer triple and all its internal pointers.
VOLK_BufferVOLK_btriple_pos (const VOLK_BufferTriple *btrp, VOLK_TriplePos n)
 Get serialized triple by term position.
VOLK_Key VOLK_btriple_hash (const VOLK_BufferTriple *strp)
 Hash a buffer triple.

Variables

VOLK_BufferVOLK_default_ctx_buf
 Serialized default context.

Detailed Description

Macro Definition Documentation

◆ NULL_KEY

#define NULL_KEY   0

"NULL" key, a value that is never user-provided.

Used to mark special values (e.g. deleted records).

Definition at line 15 of file buffer.h.

◆ BUF_DUMMY

#define BUF_DUMMY   VOLK_buffer_new (NULL, 0)

Dummy buffer to be used with VOLK_buffer_init.

Definition at line 154 of file buffer.h.

◆ BTRP_DUMMY

#define BTRP_DUMMY   VOLK_btriple_new (BUF_DUMMY, BUF_DUMMY, BUF_DUMMY)

Dummy buffer triple.

Triple of dummy buffer, with VOLK_Buffer size space allocated, but no contents.

Free with VOLK_btriple_free().

Definition at line 336 of file buffer.h.

Enumeration Type Documentation

◆ VOLK_TriplePos

Triple position of s, p, o.

Enumerator
TRP_POS_S 
TRP_POS_P 
TRP_POS_O 

Definition at line 19 of file buffer.h.

◆ VOLK_BufferFlag

Buffer flags, stored in buffer structure.

Enumerator
VOLK_BUF_BORROWED 

Borrowed buffer. This indicates that the memory block pointed to by the buffer is owned by another function, and instructs VOLK_buffer_free() to only free the buffer handle, but not the underlying data.

Definition at line 27 of file buffer.h.

Function Documentation

◆ VOLK_buffer_init()

VOLK_rc VOLK_buffer_init ( VOLK_Buffer * buf,
const size_t size,
const unsigned char * data )

Initialize or reuse a buffer handle.

The handle must have been created with VOLK_buffer_new*().

The data block is resized without being freed first. The handle must be eventually freed with VOLK_buffer_done() after use.

Parameters
[in]bufA buffer handle obtained with VOLK_buffer_new or by manual allocation.
[in]sizeNew size.
[in]dataIf not NULL, data to replace the existing ones. The size of the data to be copied is determined by the size parameter. If NULL, the existing data are preserved as with a normal realloc().

Definition at line 18 of file buffer.c.

◆ VOLK_buffer_new()

VOLK_Buffer * VOLK_buffer_new ( const unsigned char * data,
const size_t size )
inline

Create a new buffer and optionally populate it with data.

To change the buffer size and/or data later call VOLK_buffer_init.

To copy a buffer just do buf2 = VOLK_buffer_new (buf1->addr, buf1->size);

Parameters
[in]sizeLength of the data.
[in]dataOptional data to initially populate the object with. If NULL, the buffer data are garbage.
Returns
VOLK_Buffer handle. It must be freed with VOLK_buffer_free. NULL on error.

Definition at line 111 of file buffer.h.

◆ VOLK_buffer_new_borrowed()

VOLK_Buffer * VOLK_buffer_new_borrowed ( unsigned char * data,
const size_t size )
inline

Create a borrowed buffer (memory view).

A borrowed buffer does not own the memory block pointed to and should not be freed. It can be identified by the VOLK_BUF_BORROWED flag.

Parameters
[in]dataAddress of data handled by the buffer.
[in]sizeLength of the data.
Returns
VOLK_Buffer handle. It must be freed with VOLK_buffer_free, which will correctly leave the underlying data alone. NULL on error.

Definition at line 139 of file buffer.h.

◆ VOLK_buffer_done()

void VOLK_buffer_done ( VOLK_Buffer * buf)

Free the content of a buffer.

Note
This function is safe to use on borrowed buffers.

Definition at line 92 of file buffer.c.

◆ VOLK_buffer_free()

void VOLK_buffer_free ( VOLK_Buffer * buf)

Free a buffer.

Note
This function is safe to use on borrowed buffers. In such case, only the VOLK_Buffer structure is freed, but not the underlying data.

Definition at line 97 of file buffer.c.

◆ VOLK_buffer_hash()

VOLK_Key VOLK_buffer_hash ( const VOLK_Buffer * buf)
inline

Hash a buffer.

Definition at line 175 of file buffer.h.

◆ VOLK_buffer_print()

void VOLK_buffer_print ( const VOLK_Buffer * buf)

Print a byte string of a given length in a human-readable format.

The string is printed in Python style: printable characters are output literally, and non-printable ones as hex sequences.

Definition at line 43 of file buffer.c.

◆ VOLK_buffer_as_str()

char * VOLK_buffer_as_str ( const VOLK_Buffer * buf)

Format a buffer into anb ASCII string.

The string has non-printable characters escaped as "\xNN".

Parameters
[in]bufBuffer to convert.
Returns
Formatted string. It must be freed with free().

Definition at line 58 of file buffer.c.

◆ VOLK_buffer_cmp()

int VOLK_buffer_cmp ( const VOLK_Buffer * buf1,
const VOLK_Buffer * buf2 )
inline

Compare two buffers.

The return value is the same as memcmp.

Definition at line 206 of file buffer.h.

◆ VOLK_buffer_eq()

bool VOLK_buffer_eq ( const VOLK_Buffer * buf1,
const VOLK_Buffer * buf2 )
inline

Return whether two buffers are equal.

This may be faster than VOLK_buffer_cmp() because it does a size comparison first.

Definition at line 219 of file buffer.h.

◆ VOLK_btriple_new()

VOLK_BufferTriple * VOLK_btriple_new ( VOLK_Buffer * s,
VOLK_Buffer * p,
VOLK_Buffer * o )

Create a new buffer triple.

Important
The triple must be freed with VOLK_btriple_free().
Parameters
[in]sSubject as a serialized buffer.
[in]pPredicate as a serialized buffer.
[in]oObject as a serialized buffer.
Returns
New triple.

Definition at line 109 of file buffer.c.

◆ VOLK_btriple_init()

VOLK_rc VOLK_btriple_init ( VOLK_BufferTriple * sspo,
VOLK_Buffer * s,
VOLK_Buffer * p,
VOLK_Buffer * o )

Initialize internal term pointers in a heap-allocated buffer triple.

Important
The triple must be freed with VOLK_btriple_free().
Parameters
[in]sspoSerialized triple pointer to initialize.
[in]sSubject as a serialized buffer.
[in]pPredicate as a serialized buffer.
[in]oObject as a serialized buffer.
Returns
VOLK_OK on success.

Definition at line 124 of file buffer.c.

◆ VOLK_btriple_done()

void VOLK_btriple_done ( VOLK_BufferTriple * sspo)

Free the internal pointers of a buffer triple.

Parameters
[in]sspoBuffer triple to be freed.

Definition at line 136 of file buffer.c.

◆ VOLK_btriple_free()

void VOLK_btriple_free ( VOLK_BufferTriple * sspo)

Free a buffer triple and all its internal pointers.

Important
If the buffer pointers are not to be freed (e.g. they are owned by a back end), use a simple free(sspo) instead of this.
Parameters
[in]sspoBuffer triple to be freed.

Definition at line 147 of file buffer.c.

◆ VOLK_btriple_pos()

VOLK_Buffer * VOLK_btriple_pos ( const VOLK_BufferTriple * btrp,
VOLK_TriplePos n )
inline

Get serialized triple by term position.

Useful for looping over all terms.

Parameters
[in]btrpSerialized triple pointer.
[in]nA number between 0รท2.
Returns
Corresponding serialized term or NULL if n is out of range.

Definition at line 297 of file buffer.h.

◆ VOLK_btriple_hash()

VOLK_Key VOLK_btriple_hash ( const VOLK_BufferTriple * strp)
inline

Hash a buffer triple.

Todo
This doesn't handle blank nodes correctly. RDF_Canon should be ported to this library.
Parameters
[in]strpSerialized triple to hash.
Returns
Hash value.

Definition at line 317 of file buffer.h.

Variable Documentation

◆ VOLK_default_ctx_buf

VOLK_Buffer* VOLK_default_ctx_buf
extern

Serialized default context.

Definition at line 5 of file buffer.c.