LMMS
Loading...
Searching...
No Matches
sord.c File Reference
#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "zix/digest.c"
#include "zix/hash.c"
#include "zix/btree.c"
#include "sord_config.h"
#include "sord_internal.h"

Classes

struct  SordWorldImpl
struct  SordModelImpl
struct  SordIterImpl

Macros

#define ZIX_INLINE
#define SORD_LOG(prefix, ...)
#define SORD_ITER_LOG(...)
#define SORD_FIND_LOG(...)
#define SORD_WRITE_LOG(...)
#define NUM_ORDERS   12
#define STATEMENT_LEN   3
#define TUP_LEN   STATEMENT_LEN + 1
#define DEFAULT_ORDER   SPO
#define DEFAULT_GRAPH_ORDER   GSPO
#define TUP_FMT   "(%s %s %s %s)"
#define TUP_FMT_ELEM(e)
#define TUP_FMT_ARGS(t)
#define TUP_S   0
#define TUP_P   1
#define TUP_O   2
#define TUP_G   3
#define PAT_CASE(sig, m, g0, g1, np)

Enumerations

enum  SordOrder {
  SPO , SOP , OPS , OSP ,
  PSO , POS , GSPO , GSOP ,
  GOPS , GOSP , GPSO , GPOS
}
enum  SearchMode {
  ALL , SINGLE , RANGE , FILTER_RANGE ,
  FILTER_ALL
}

Functions

static uint32_t sord_node_hash (const void *n)
static bool sord_node_hash_equal (const void *a, const void *b)
static void error (SordWorld *world, SerdStatus st, const char *fmt,...)
SordWorldsord_world_new (void)
static void free_node_entry (void *value, void *user_data)
void sord_world_free (SordWorld *world)
void sord_world_set_error_sink (SordWorld *world, SerdErrorSink error_sink, void *handle)
static int sord_node_compare (const SordNode *a, const SordNode *b)
bool sord_node_equals (const SordNode *a, const SordNode *b)
static bool sord_id_match (const SordNode *a, const SordNode *b)
static bool sord_quad_match_inline (const SordQuad x, const SordQuad y)
bool sord_quad_match (const SordQuad x, const SordQuad y)
static int sord_quad_compare (const void *x_ptr, const void *y_ptr, void *user_data)
static bool sord_iter_forward (SordIter *iter)
static bool sord_iter_seek_match (SordIter *iter)
static bool sord_iter_seek_match_range (SordIter *iter)
static SordItersord_iter_new (const SordModel *sord, ZixBTreeIter *cur, const SordQuad pat, SordOrder order, SearchMode mode, int n_prefix)
const SordModelsord_iter_get_model (SordIter *iter)
void sord_iter_get (const SordIter *iter, SordQuad id)
const SordNodesord_iter_get_node (const SordIter *iter, SordQuadIndex index)
static bool sord_iter_scan_next (SordIter *iter)
bool sord_iter_next (SordIter *iter)
bool sord_iter_end (const SordIter *iter)
void sord_iter_free (SordIter *iter)
static bool sord_has_index (SordModel *sord, SordOrder *order, int *n_prefix, bool graphs)
static SordOrder sord_best_index (SordModel *sord, const SordQuad pat, SearchMode *mode, int *n_prefix)
SordModelsord_new (SordWorld *world, unsigned indices, bool graphs)
static void sord_node_free_internal (SordWorld *world, SordNode *node)
static void sord_add_quad_ref (SordModel *sord, const SordNode *node, SordQuadIndex i)
static void sord_drop_quad_ref (SordModel *sord, const SordNode *node, SordQuadIndex i)
void sord_free (SordModel *sord)
SordWorldsord_get_world (SordModel *sord)
size_t sord_num_quads (const SordModel *sord)
size_t sord_num_nodes (const SordWorld *world)
SordItersord_begin (const SordModel *sord)
SordItersord_find (SordModel *sord, const SordQuad pat)
SordItersord_search (SordModel *model, const SordNode *s, const SordNode *p, const SordNode *o, const SordNode *g)
SordNodesord_get (SordModel *model, const SordNode *s, const SordNode *p, const SordNode *o, const SordNode *g)
bool sord_ask (SordModel *model, const SordNode *s, const SordNode *p, const SordNode *o, const SordNode *g)
uint64_t sord_count (SordModel *model, const SordNode *s, const SordNode *p, const SordNode *o, const SordNode *g)
bool sord_contains (SordModel *sord, const SordQuad pat)
static uint8_tsord_strndup (const uint8_t *str, size_t len)
SordNodeType sord_node_get_type (const SordNode *node)
const uint8_tsord_node_get_string (const SordNode *node)
const uint8_tsord_node_get_string_counted (const SordNode *node, size_t *bytes)
const uint8_tsord_node_get_string_measured (const SordNode *node, size_t *bytes, size_t *chars)
const char * sord_node_get_language (const SordNode *node)
SordNodesord_node_get_datatype (const SordNode *node)
SerdNodeFlags sord_node_get_flags (const SordNode *node)
bool sord_node_is_inline_object (const SordNode *node)
static SordNodesord_insert_node (SordWorld *world, const SordNode *key, bool copy)
static SordNodesord_new_uri_counted (SordWorld *world, const uint8_t *str, size_t n_bytes, size_t n_chars, bool copy)
SordNodesord_new_uri (SordWorld *world, const uint8_t *str)
SordNodesord_new_relative_uri (SordWorld *world, const uint8_t *str, const uint8_t *base_str)
static SordNodesord_new_blank_counted (SordWorld *world, const uint8_t *str, size_t n_bytes, size_t n_chars)
SordNodesord_new_blank (SordWorld *world, const uint8_t *str)
static SordNodesord_new_literal_counted (SordWorld *world, SordNode *datatype, const uint8_t *str, size_t n_bytes, size_t n_chars, SerdNodeFlags flags, const char *lang)
SordNodesord_new_literal (SordWorld *world, SordNode *datatype, const uint8_t *str, const char *lang)
SordNodesord_node_from_serd_node (SordWorld *world, SerdEnv *env, const SerdNode *sn, const SerdNode *datatype, const SerdNode *lang)
const SerdNodesord_node_to_serd_node (const SordNode *node)
void sord_node_free (SordWorld *world, SordNode *node)
SordNodesord_node_copy (const SordNode *node)
static bool sord_add_to_index (SordModel *sord, const SordNode **tup, SordOrder order)
bool sord_add (SordModel *sord, const SordQuad tup)
void sord_remove (SordModel *sord, const SordQuad tup)
SerdStatus sord_erase (SordModel *sord, SordIter *iter)

Variables

static const int orderings [NUM_ORDERS][TUP_LEN]

Macro Definition Documentation

◆ DEFAULT_GRAPH_ORDER

#define DEFAULT_GRAPH_ORDER   GSPO

◆ DEFAULT_ORDER

#define DEFAULT_ORDER   SPO

◆ NUM_ORDERS

#define NUM_ORDERS   12

◆ PAT_CASE

#define PAT_CASE ( sig,
m,
g0,
g1,
np )
Value:
case sig: \
*mode = m; \
good[0] = g0; \
good[1] = g1; \
*n_prefix = np; \
break
unsigned * m
Definition inflate.c:1559
png_structrp int mode
Definition png.h:1139

◆ SORD_FIND_LOG

#define SORD_FIND_LOG ( ...)

◆ SORD_ITER_LOG

#define SORD_ITER_LOG ( ...)

◆ SORD_LOG

#define SORD_LOG ( prefix,
... )
Value:
fprintf(stderr, "[Sord::" prefix "] " __VA_ARGS__)

◆ SORD_WRITE_LOG

#define SORD_WRITE_LOG ( ...)

◆ STATEMENT_LEN

#define STATEMENT_LEN   3

◆ TUP_FMT

#define TUP_FMT   "(%s %s %s %s)"

◆ TUP_FMT_ARGS

#define TUP_FMT_ARGS ( t)
Value:
TUP_FMT_ELEM((t)[0]), \
TUP_FMT_ELEM((t)[1]), \
TUP_FMT_ELEM((t)[2]), \
TUP_FMT_ELEM((t)[3])
struct huft * t
Definition inflate.c:943
#define TUP_FMT_ELEM(e)
Definition sord.c:70

◆ TUP_FMT_ELEM

#define TUP_FMT_ELEM ( e)
Value:
* e
Definition inflate.c:1404
SORD_API const uint8_t * sord_node_get_string(const SordNode *node)
Definition sord.c:997
unsigned char uint8_t
Definition mid.cpp:98
#define const
Definition zconf.h:137

◆ TUP_G

#define TUP_G   3

◆ TUP_LEN

#define TUP_LEN   STATEMENT_LEN + 1

◆ TUP_O

#define TUP_O   2

◆ TUP_P

#define TUP_P   1

◆ TUP_S

#define TUP_S   0

◆ ZIX_INLINE

#define ZIX_INLINE

Enumeration Type Documentation

◆ SearchMode

enum SearchMode

Mode for searching or iteration

Enumerator
ALL 

Iterate over entire store.

SINGLE 

Iteration over a single element (exact search).

RANGE 

Iterate over range with equal prefix.

FILTER_RANGE 

Iterate over range with equal prefix, filtering.

FILTER_ALL 

Iterate to end of store, filtering.

◆ SordOrder

enum SordOrder

Triple ordering

Enumerator
SPO 

Subject, Predicate, Object.

SOP 

Subject, Object, Predicate.

OPS 

Object, Predicate, Subject.

OSP 

Object, Subject, Predicate.

PSO 

Predicate, Subject, Object.

POS 

Predicate, Object, Subject.

GSPO 

Graph, Subject, Predicate, Object.

GSOP 

Graph, Subject, Object, Predicate.

GOPS 

Graph, Object, Predicate, Subject.

GOSP 

Graph, Object, Subject, Predicate.

GPSO 

Graph, Predicate, Subject, Object.

GPOS 

Graph, Predicate, Object, Subject.

Function Documentation

◆ error()

void error ( SordWorld * world,
SerdStatus st,
const char * fmt,
... )
static

◆ free_node_entry()

void free_node_entry ( void * value,
void * user_data )
static

◆ sord_add_quad_ref()

void sord_add_quad_ref ( SordModel * sord,
const SordNode * node,
SordQuadIndex i )
static

◆ sord_add_to_index()

bool sord_add_to_index ( SordModel * sord,
const SordNode ** tup,
SordOrder order )
inlinestatic

◆ sord_best_index()

SordOrder sord_best_index ( SordModel * sord,
const SordQuad pat,
SearchMode * mode,
int * n_prefix )
inlinestatic

Return the best available index for a pattern.

Parameters
patPattern in standard (S P O G) order
modeSet to the (best) iteration mode for iterating over results
n_prefixSet to the length of the range prefix (for mode == RANGE and mode == FILTER_RANGE)

◆ sord_drop_quad_ref()

void sord_drop_quad_ref ( SordModel * sord,
const SordNode * node,
SordQuadIndex i )
static

◆ sord_has_index()

bool sord_has_index ( SordModel * sord,
SordOrder * order,
int * n_prefix,
bool graphs )
inlinestatic

Return true iff Sord has an index for order. If graphs is true, order will be modified to be the corresponding order with a G prepended (so G will be the MSN).

◆ sord_id_match()

bool sord_id_match ( const SordNode * a,
const SordNode * b )
inlinestatic

Return true iff IDs are equivalent, or one is a wildcard

◆ sord_insert_node()

SordNode * sord_insert_node ( SordWorld * world,
const SordNode * key,
bool copy )
static

◆ sord_iter_forward()

bool sord_iter_forward ( SordIter * iter)
inlinestatic

◆ sord_iter_new()

SordIter * sord_iter_new ( const SordModel * sord,
ZixBTreeIter * cur,
const SordQuad pat,
SordOrder order,
SearchMode mode,
int n_prefix )
static

◆ sord_iter_scan_next()

bool sord_iter_scan_next ( SordIter * iter)
static

◆ sord_iter_seek_match()

bool sord_iter_seek_match ( SordIter * iter)
inlinestatic

Seek forward as necessary until iter points at a match.

Returns
true iff iterator reached end of valid range.

◆ sord_iter_seek_match_range()

bool sord_iter_seek_match_range ( SordIter * iter)
inlinestatic

Seek forward as necessary until iter points at a match, or the prefix no longer matches iter->pat.

Returns
true iff iterator reached end of valid range.

◆ sord_new_blank_counted()

SordNode * sord_new_blank_counted ( SordWorld * world,
const uint8_t * str,
size_t n_bytes,
size_t n_chars )
static

◆ sord_new_literal_counted()

SordNode * sord_new_literal_counted ( SordWorld * world,
SordNode * datatype,
const uint8_t * str,
size_t n_bytes,
size_t n_chars,
SerdNodeFlags flags,
const char * lang )
static

◆ sord_new_uri_counted()

SordNode * sord_new_uri_counted ( SordWorld * world,
const uint8_t * str,
size_t n_bytes,
size_t n_chars,
bool copy )
static

◆ sord_node_compare()

int sord_node_compare ( const SordNode * a,
const SordNode * b )
inlinestatic

Compare nodes, considering NULL a wildcard match.

◆ sord_node_free_internal()

void sord_node_free_internal ( SordWorld * world,
SordNode * node )
static

◆ sord_node_hash()

uint32_t sord_node_hash ( const void * n)
static

◆ sord_node_hash_equal()

bool sord_node_hash_equal ( const void * a,
const void * b )
static

◆ sord_quad_compare()

int sord_quad_compare ( const void * x_ptr,
const void * y_ptr,
void * user_data )
static

Compare two quad IDs lexicographically. NULL IDs (equal to 0) are treated as wildcards, always less than every other possible ID, except itself.

◆ sord_quad_match_inline()

bool sord_quad_match_inline ( const SordQuad x,
const SordQuad y )
inlinestatic

◆ sord_strndup()

uint8_t * sord_strndup ( const uint8_t * str,
size_t len )
static

Variable Documentation

◆ orderings

const int orderings[NUM_ORDERS][TUP_LEN]
static
Initial value:
= {
{ 0, 1, 2, 3 }, { 0, 2, 1, 3 },
{ 2, 1, 0, 3 }, { 2, 0, 1, 3 },
{ 1, 0, 2, 3 }, { 1, 2, 0, 3 },
{ 3, 0, 1, 2 }, { 3, 0, 2, 1 },
{ 3, 2, 1, 0 }, { 3, 2, 0, 1 },
{ 3, 1, 0, 2 }, { 3, 1, 2, 0 }
}

Quads of indices for each order, from most to least significant (array indexed by SordOrder)