123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- #ifndef _LSUP_TERM_H
- #define _LSUP_TERM_H
- #include <assert.h>
- #include <regex.h>
- #include "uthash.h"
- #include "buffer.h"
- #include "namespace.h"
- #define UUID4_URN_SIZE UUIDSTR_SIZE + 10
- #define LSUP_TERM_UNDEFINED 0
- #define LSUP_TERM_IRIREF 1
- #define LSUP_TERM_NS_IRIREF 2
- #define LSUP_TERM_LITERAL 3
- #define LSUP_TERM_LT_LITERAL 4
- #define LSUP_TERM_BNODE 5
- #define DEFAULT_DTYPE "http://www.w3.org/2001/XMLSchema#string"
- #define LSUP_URI_REGEX_STR \
- "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"
- typedef XXH64_hash_t LSUP_Hash64;
- typedef char LSUP_TermType;
- typedef char LSUP_LangTag[8];
- typedef struct term_t {
- char * data;
- union {
- LSUP_Key datatype;
- LSUP_LangTag lang;
- LSUP_Key bnode_id;
- LSUP_NSMap * nsm;
- };
- LSUP_TermType type;
- } LSUP_Term;
- struct term_cache_t {
- LSUP_Key key;
- LSUP_Term * term;
- UT_hash_handle hh;
- };
- typedef struct triple_t {
- LSUP_Term *s;
- LSUP_Term *p;
- LSUP_Term *o;
- } LSUP_Triple;
- extern struct term_cache_t *LSUP_term_cache;
- extern uint32_t LSUP_default_dtype_key;
- extern regex_t *LSUP_uri_ptn;
- extern LSUP_Term *LSUP_default_datatype;
- LSUP_Term *
- LSUP_term_new (LSUP_TermType type, const char *data, void *metadata);
- #define TERM_DUMMY LSUP_term_new (LSUP_TERM_UNDEFINED, NULL, NULL)
- inline LSUP_Term *
- LSUP_uri_new (const char *data)
- {
- return LSUP_term_new (LSUP_TERM_IRIREF, data, NULL);
- }
- LSUP_rc
- LSUP_term_init(
- LSUP_Term *term, LSUP_TermType type,
- const char *data, void *metadata);
- LSUP_Term *
- LSUP_term_new_from_buffer (const LSUP_Buffer *sterm);
- LSUP_Buffer *
- LSUP_term_serialize (const LSUP_Term *term);
- inline LSUP_rc
- LSUP_uri_init (LSUP_Term *term, const char *data)
- { return LSUP_term_init (term, LSUP_TERM_IRIREF, data, NULL); }
- LSUP_Key
- LSUP_term_hash (const LSUP_Term *term);
- bool LSUP_term_equals (const LSUP_Term *term1, const LSUP_Term *term2);
- void
- LSUP_term_done (LSUP_Term *term);
- void
- LSUP_term_free (LSUP_Term *term);
- LSUP_Triple *
- LSUP_triple_new(LSUP_Term *s, LSUP_Term *p, LSUP_Term *o);
- #define TRP_DUMMY LSUP_triple_new (NULL, NULL, NULL)
- LSUP_Triple *
- LSUP_triple_new_from_btriple (const LSUP_BufferTriple *sspo);
- LSUP_BufferTriple *
- LSUP_triple_serialize (const LSUP_Triple *spo);
- LSUP_rc
- LSUP_triple_init (LSUP_Triple *spo, LSUP_Term *s, LSUP_Term *p, LSUP_Term *o);
- void
- LSUP_triple_done (LSUP_Triple *spo);
- void
- LSUP_triple_free (LSUP_Triple *spo);
- inline LSUP_Term *
- LSUP_triple_pos (const LSUP_Triple *trp, LSUP_TriplePos n)
- {
- if (n == TRP_POS_S) return trp->s;
- if (n == TRP_POS_P) return trp->p;
- if (n == TRP_POS_O) return trp->o;
- return NULL;
- }
- inline LSUP_Key
- LSUP_triple_hash (const LSUP_Triple *trp)
- {
- LSUP_BufferTriple *strp = LSUP_triple_serialize (trp);
- LSUP_Key hash = LSUP_btriple_hash (strp);
- LSUP_btriple_free (strp);
- return hash;
- }
- LSUP_rc
- LSUP_tcache_add (const LSUP_Key key, LSUP_Term *term);
- const LSUP_Term *
- LSUP_tcache_get (const LSUP_Key key);
- #endif
|