1 /*  Part of SWI-Prolog
2 
3     Author:        Jan Wielemaker
4     E-mail:        J.Wielemaker@vu.nl
5     WWW:           http://www.swi-prolog.org
6     Copyright (c)  2003-2016, University of Amsterdam
7                               VU University Amsterdam
8     All rights reserved.
9 
10     Redistribution and use in source and binary forms, with or without
11     modification, are permitted provided that the following conditions
12     are met:
13 
14     1. Redistributions of source code must retain the above copyright
15        notice, this list of conditions and the following disclaimer.
16 
17     2. Redistributions in binary form must reproduce the above copyright
18        notice, this list of conditions and the following disclaimer in
19        the documentation and/or other materials provided with the
20        distribution.
21 
22     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26     COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33     POSSIBILITY OF SUCH DAMAGE.
34 */
35 
36 #ifndef RDFDB_H_INCLUDED
37 #define RDFDB_H_INCLUDED
38 #include <config.h>
39 
40 		 /*******************************
41 		 *	     OPTIONS		*
42 		 *******************************/
43 
44 #define WITH_MD5 1
45 #if SIZEOF_VOIDP > 6
46 #define COMPACT  1
47 #endif
48 
49 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50 Symbols are local to shared objects  by   default  in  COFF based binary
51 formats, and public in ELF based formats.   In some ELF based systems it
52 is possible to make them local   anyway. This enhances encapsulation and
53 avoids an indirection for calling these   functions.  Functions that are
54 supposed to be local to the SWI-Prolog kernel are declared using
55 
56     COMMON(<type) <function>(<args>);
57 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
58 
59 #ifdef HAVE_VISIBILITY_ATTRIBUTE
60 #define SO_LOCAL __attribute__((visibility("hidden")))
61 #else
62 #define SO_LOCAL
63 #endif
64 #define COMMON(type) SO_LOCAL type
65 
66 		 /*******************************
67 		 *	   OTHER MODULES	*
68 		 *******************************/
69 
70 #include <SWI-Stream.h>
71 #include <SWI-Prolog.h>
72 #include <assert.h>
73 #include <string.h>
74 #include "atom.h"
75 #include "deferfree.h"
76 #include "debug.h"
77 #include "memory.h"
78 #include "hash.h"
79 #include "skiplist.h"
80 #ifdef WITH_MD5
81 #include "md5.h"
82 #endif
83 #include "mutex.h"
84 #include "resource.h"
85 #include "xsd.h"
86 
87 #define RDF_VERSION 30000		/* 3.0.0 */
88 
89 #define URL_subPropertyOf "http://www.w3.org/2000/01/rdf-schema#subPropertyOf"
90 
91 
92 		 /*******************************
93 		 *	       LOCKING		*
94 		 *******************************/
95 
96 #define MUST_HOLD(lock)			((void)0)
97 #define LOCK_MISC(db)			simpleMutexLock(&db->locks.misc)
98 #define UNLOCK_MISC(db)			simpleMutexUnlock(&db->locks.misc)
99 
100 
101 		 /*******************************
102 		 *	    GENERATIONS		*
103 		 *******************************/
104 
105 typedef uint64_t gen_t;			/* Basic type for generations */
106 
107 typedef struct lifespan
108 { gen_t		born;			/* Generation we were born */
109   gen_t		died;			/* Generation we died */
110 } lifespan;
111 
112 #define GEN_UNDEF	0xffffffffffffffff /* no defined generation */
113 #define GEN_MAX		0x7fffffffffffffff /* Max `normal' generation */
114 #define GEN_PREHIST	0x0000000000000000 /* The prehistoric generation */
115 #define GEN_EPOCH	0x0000000000000001 /* The generation epoch */
116 #define GEN_TBASE	0x8000000000000000 /* Transaction generation base */
117 #define GEN_TNEST	0x0000000100000000 /* Max transaction nesting */
118 
119 					/* Generation of a transaction */
120 #define T_GEN(tid,d)	(GEN_TBASE + (tid)*GEN_TNEST + (d))
121 
122 #include "snapshot.h"
123 
124 
125 		 /*******************************
126 		 *	       TRIPLES		*
127 		 *******************************/
128 
129 /* Keep consistent with md5_type[] in rdf_db.c! */
130 #define OBJ_UNTYPED	0x0		/* partial: don't know */
131 #define OBJ_INTEGER	0x1
132 #define OBJ_DOUBLE	0x2
133 #define OBJ_STRING	0x3
134 #define OBJ_TERM	0x4
135 
136 #define Q_NONE		0x0
137 #define Q_TYPE		0x1
138 #define Q_LANG		0x2
139 
140 #define BY_NONE	0x00			/* 0 */
141 #define BY_S	0x01			/* 1 */
142 #define BY_P	0x02			/* 2 */
143 #define BY_O	0x04			/* 4 */
144 #define BY_G	0x08			/* 8 */
145 #define BY_SP	(BY_S|BY_P)		/* 3 */
146 #define BY_SO	(BY_S|BY_O)		/* 5 */
147 #define BY_PO	(BY_P|BY_O)		/* 6 */
148 #define BY_SPO	(BY_S|BY_P|BY_O)	/* 7 */
149 #define BY_SG	(BY_S|BY_G)		/* 9 */
150 #define BY_PG	(BY_P|BY_G)		/* 10 */
151 #define BY_SPG	(BY_S|BY_P|BY_G)	/* 11 */
152 #define BY_OG	(BY_O|BY_G)		/* 12 */
153 #define BY_SOG	(BY_S|BY_O|BY_G)	/* 13 */
154 #define BY_POG	(BY_P|BY_O|BY_G)	/* 14 */
155 #define BY_SPOG	(BY_S|BY_P|BY_O|BY_G)	/* 15 */
156 
157 /* (*) INDEX_TABLES must be consistent with index_col[] in rdf_db.c */
158 #define INDEX_TABLES		        10	/* (*)  */
159 #define INITIAL_TABLE_SIZE		1024
160 #define INITIAL_RESOURCE_TABLE_SIZE	8192
161 #define INITIAL_PREDICATE_TABLE_SIZE	64
162 #define INITIAL_GRAPH_TABLE_SIZE	64
163 
164 #define DUPLICATE_ADMIN_THRESHOLD	1024
165 
166 #define MAX_HASH_FACTOR 8		/* factor to trigger re-hash */
167 #define MIN_HASH_FACTOR 4		/* factor after re-hash */
168 
169 #define NO_LINE	(0)
170 
171 typedef struct cell
172 { void *	value;			/* represented resource */
173   struct cell  *next;			/* next in chain */
174 } cell;
175 
176 
177 typedef struct list
178 { cell *head;				/* first in list */
179   cell *tail;				/* tail of list */
180 } list;
181 
182 
183 typedef struct bitmatrix
184 { size_t width;
185   size_t heigth;
186   int bits[1];
187 } bitmatrix;
188 
189 
190 typedef struct is_leaf
191 { struct is_leaf *older;		/* Older is_leaf info */
192   lifespan	lifespan;		/* Computed for this lifespan */
193   int		is_leaf;		/* Predicate was a leaf then */
194 } is_leaf;
195 
196 #define DISTINCT_DIRECT 0		/* for ->distinct_subjects, etc */
197 #define DISTINCT_SUB    1
198 
199 typedef struct predicate
200 { atom_t	    name;		/* name of the predicate */
201   struct predicate *next;		/* next in hash-table */
202 					/* hierarchy */
203   list	            subPropertyOf;	/* the one I'm subPropertyOf */
204   list	            siblings;		/* reverse of subPropertyOf */
205   struct predicate_cloud *cloud;	/* cloud I belong to */
206   is_leaf	   *is_leaf;		/* cached is-leaf information */
207   struct predicate *inverse_of;		/* my inverse predicate */
208   unsigned int	    hash;		/* key used for hashing */
209   unsigned int	    label : 24;		/* Numeric label in cloud */
210   unsigned	    transitive : 1;	/* P(a,b)&P(b,c) --> P(a,c) */
211 					/* statistics */
212   size_t	    triple_count;	/* # triples on this predicate */
213   size_t	    distinct_updated[2];/* Is count still valid? */
214   size_t	    distinct_count[2];  /* Triple count at last update */
215   size_t	    distinct_subjects[2];/* # distinct subject values */
216   size_t	    distinct_objects[2];/* # distinct object values */
217 } predicate;
218 
219 #define MAX_PBLOCKS 32
220 
221 typedef struct pred_hash
222 { predicate   **blocks[MAX_PBLOCKS];	/* Dynamic array starts */
223   size_t	bucket_count;		/* Allocated #buckets */
224   size_t	bucket_count_epoch;	/* Initial bucket count */
225   size_t	count;			/* Total #predicates */
226 } pred_hash;
227 
228 
229 typedef struct sub_p_matrix
230 { struct sub_p_matrix *older;		/* Reachability for older gen */
231   lifespan      lifespan;		/* Lifespan this matrix is valid */
232   bitmatrix    *matrix;			/* Actual reachability matrix */
233 } sub_p_matrix;
234 
235 
236 typedef struct predicate_cloud
237 { struct predicate_cloud *merged_into;	/* Cloud was merged into target */
238   sub_p_matrix *reachable;		/* cloud reachability matrices */
239   predicate   **members;		/* member predicates */
240   size_t	size;			/* size of the cloud */
241   size_t	deleted;		/* See erase_predicates() */
242   size_t	alt_hash_count;		/* Alternative hashes */
243   unsigned int *alt_hashes;
244   unsigned int  hash;			/* hash-code */
245   int		last_gc;		/* number of last gc */
246 } predicate_cloud;
247 
248 
249 typedef struct graph
250 { struct graph *next;			/* next in table */
251   atom_t	name;			/* name of the graph */
252   atom_t	source;			/* URL graph was loaded from */
253   double	modified;		/* Modified time of source URL */
254   int		triple_count;		/* # triples associated to it */
255   unsigned	erased;			/* Graph is destroyed */
256 #ifdef WITH_MD5
257   unsigned	md5 : 1;		/* do/don't record MD5 */
258   md5_byte_t	digest[16];		/* MD5 digest */
259   md5_byte_t	unmodified_digest[16];	/* MD5 digest when unmodified */
260 #endif
261 } graph;
262 
263 #define MAX_GBLOCKS 32
264 
265 typedef struct graph_hash_table
266 { graph	      **blocks[MAX_GBLOCKS];	/* Dynamic array starts */
267   size_t	bucket_count;		/* Allocated #buckets */
268   size_t	bucket_count_epoch;	/* Initial bucket count */
269   size_t	count;			/* Total #predicates */
270   size_t	erased;			/* erased and not reclaimed graphs */
271 } graph_hash_table;
272 
273 typedef struct literal
274 { union
275   { atom_t	string;
276     int64_t	integer;
277     double	real;
278     struct
279     { record_t  record;
280       size_t	len;
281     } term;				/* external record */
282   } value;
283   atom_id	type_or_lang;		/* Type or language for literals */
284   unsigned int  hash;			/* saved hash */
285   unsigned int	references;		/* # references to me */
286   unsigned	objtype : 3;
287   unsigned	qualifier : 2;		/* Lang/Type qualifier */
288   unsigned	shared : 1;		/* member of shared table */
289   unsigned	term_loaded : 1;	/* OBJ_TERM from quick save file */
290   unsigned	atoms_locked : 1;	/* Atoms have been locked */
291 } literal;
292 
293 
294 #define t_match next[0]
295 
296 #ifdef COMPACT
297 #define TRIPLE_NO_ID	(0)
298 typedef unsigned int triple_id;		/* Triple identifier */
299 #endif
300 
301 #ifdef TRIPLE_MAGIC
302 
303 typedef enum
304 { T_CHAINED1 = TRIPLE_MAGIC,		/* Added to hash-chains */
305   T_CHAINED2,				/* Added to hash as reindexed */
306   T_REINDEXED,				/* Reindexed (waiting for GC) */
307   T_LINGERING,				/* waiting to be freed */
308   T_FREED				/* freed */
309 } triple_status;
310 
311 #define TMAGIC(t, s) (t->magic = s)
312 
313 #else
314 
315 #define TMAGIC(t, s) (void)0
316 
317 #endif
318 
319 typedef struct triple
320 { lifespan	lifespan;		/* Start and end generation */
321   atom_id	subject_id;
322   atom_id	graph_id;		/* where it comes from */
323   union
324   { predicate*	r;			/* resolved: normal DB */
325     atom_t	u;			/* used by rdf_load_db_/3 */
326   } predicate;
327   union
328   { literal *	literal;
329     atom_t	resource;
330   } object;
331 #ifdef COMPACT
332   triple_id	id;			/* Indentifier number */
333   triple_id	reindexed;		/* Remapped by optimize_triple_hash() */
334 #else
335   struct triple *reindexed;		/* Remapped by optimize_triple_hash() */
336 #endif
337 					/* indexing */
338   union
339   { literal	end;			/* end for between(X,Y) patterns */
340 #ifdef COMPACT
341     triple_id	next[INDEX_TABLES];	/* hash-table next identifier */
342 #else
343     struct triple*next[INDEX_TABLES];	/* hash-table next links */
344 #endif
345   } tp;					/* triple or pattern */
346 					/* smaller objects (e.g., flags) */
347   uint32_t      line;			/* graph-line number */
348   unsigned	object_is_literal : 1;	/* Object is a literal */
349   unsigned	resolve_pred : 1;	/* predicates needs to be resolved */
350   unsigned	indexed : 4;		/* Partials: BY_* */
351   unsigned	match   : 4;		/* How to match literals */
352   unsigned	inversed : 1;		/* Partials: using inverse match */
353   unsigned	is_duplicate : 1;	/* I'm a duplicate */
354   unsigned	allocated : 1;		/* Triple is allocated */
355   unsigned	atoms_locked : 1;	/* Atoms have been locked */
356   unsigned	linked : 4;		/* Linked into the hash-chains */
357   unsigned	loaded : 1;		/* for EV_ASSERT_LOAD */
358   unsigned	erased : 1;		/* Consistency of erased */
359   unsigned	lingering : 1;		/* Deleted; waiting for GC */
360   unsigned	has_reindex_prev : 1;	/* some ->reindexed points to me */
361 					/* Total: 32 */
362 #ifdef TRIPLE_MAGIC
363   triple_status	magic;
364 #endif
365 } triple;
366 
367 
368 typedef struct active_transaction
369 { struct active_transaction *parent;
370   term_t id;
371 } active_transaction;
372 
373 
374 typedef struct triple_bucket
375 {
376 #ifdef COMPACT
377   triple_id     head;			/* head of triple-list */
378   triple_id     tail;			/* Tail of triple-list */
379 #else
380   triple       *head;			/* head of triple-list */
381   triple       *tail;			/* Tail of triple-list */
382 #endif
383   unsigned int	count;			/* #Triples in bucket */
384 } triple_bucket;
385 
386 
387 #define MAX_TBLOCKS 32
388 
389 #ifdef COMPACT
390 #define TRIPLE_ARRAY_PREINIT 512
391 
392 typedef union triple_element
393 { triple *triple;			/* points to a triple */
394   union triple_element *fnext;		/* poins to another free */
395 } triple_element;
396 
397 typedef struct triple_array
398 { triple_element *blocks[MAX_TBLOCKS];	/* Dynamic array starts */
399   triple_element *freelist;		/* free buckets */
400   size_t	preinit;		/* Preinitialized size */
401   size_t	size;			/* current (allocated) size */
402 } triple_array;
403 #endif /*COMPACT*/
404 
405 typedef struct triple_hash
406 { triple_bucket	*blocks[MAX_TBLOCKS];	/* Dynamic array starts */
407   size_t	bucket_count;		/* Allocated #buckets */
408   size_t	bucket_count_epoch;	/* Initial bucket count */
409   size_t	bucket_preinit;		/* Pre-initializaed bucket count */
410   int		created;		/* Hash has been initialized */
411   int		icol;			/* ICOL of hash */
412   unsigned int	user_size;		/* User selected size as 2^N */
413   unsigned int	optimize_threshold;	/* # resizes to leave behind */
414   unsigned int	avg_chain_len;		/* Accepted average chain length */
415 } triple_hash;
416 
417 typedef struct triple_walker
418 { size_t	unbounded_hash;		/* The unbounded hash-key */
419   int		icol;			/* index column */
420   size_t	bcount;			/* Current bucket count */
421   triple       *current;		/* Our current location */
422   struct rdf_db *db;			/* the array of triples */
423 } triple_walker;
424 
425 #define MAX_BLOCKS 20			/* allows for 2M threads */
426 
427 typedef struct per_thread
428 { struct thread_info **blocks[MAX_BLOCKS];
429 } per_thread;
430 
431 typedef struct query_admin
432 { gen_t		generation;		/* Global heart-beat */
433   struct
434   { simpleMutex	lock;			/* used to lock creation of per_thread */
435     per_thread	per_thread;
436     int		thread_max;		/* highest thread seen  */
437   } query;				/* active query administration */
438   struct
439   { simpleMutex	lock;			/* Locks writing triples */
440     simpleMutex generation_lock;	/* Interlocked fix of generations */
441   } write;				/* write administration */
442 } query_admin;
443 
444 
445 #define PREFIX_INITIAL_ENTRIES 16
446 
447 typedef struct prefix
448 { atom_t	 alias;
449   atom_info      uri;
450   struct prefix *next;
451 } prefix;
452 
453 typedef struct prefix_table
454 { prefix       **entries;
455   size_t	 size;
456   size_t	 count;
457 } prefix_table;
458 
459 #define JOINED_DEFER 1
460 
461 #ifdef JOINED_DEFER
462 #define defer_triples  defer_all	/* Use the same for now */
463 #define defer_clouds   defer_all
464 #define defer_literals defer_all
465 #endif
466 
467 typedef struct rdf_db
468 { triple_bucket by_none;		/* Plain linked list of triples */
469   triple_hash   hash[INDEX_TABLES];	/* Hash-tables */
470 #ifdef COMPACT
471   triple_array	triple_array;		/* Dynamic array of triples */
472 #endif
473   size_t	created;		/* #triples created */
474   size_t	erased;			/* #triples erased */
475   size_t	reindexed;		/* #triples reindexed (gc_hash_chain) */
476   size_t	lingering;		/* #triples lingering to be freed */
477   size_t	indexed[16];		/* Count calls (2**4 possible indices) */
478   resource_db	resources;		/* admin of used resources */
479   pred_hash	predicates;		/* Predicate table */
480   size_t	agenda_created;		/* #visited nodes in agenda */
481   graph_hash_table graphs;		/* Graph table */
482   graph	       *last_graph;		/* last accessed graph */
483   prefix_table *prefixes;		/* alias->uri table */
484   query_admin	queries;		/* Active query administration */
485 
486   size_t	duplicates;		/* #duplicate triples */
487   int		maintain_duplicates;	/* If TRUE, updated duplicates */
488   int		duplicates_up_to_date;	/* Duplicate status is up-to-date */
489   size_t	duplicate_admin_threshold;	/* Maintain above this */
490 
491 #if JOINED_DEFER			/* Deferred free handling */
492   defer_free	defer_all;
493 #else
494   defer_free	defer_triples;		/* triples */
495   defer_free	defer_clouds;		/* Predicate clouds */
496   defer_free	defer_literals;		/* Literals */
497 #endif
498 
499   int		resetting;		/* We are in rdf_reset_db() */
500 
501   struct
502   { int		count;			/* # garbage collections */
503     int		busy;			/* Processing a GC */
504     int		thread_started;		/* GC thread has been started */
505     double	time;			/* time spent in GC */
506     size_t	reclaimed_triples;	/* # reclaimed triples */
507     size_t	reclaimed_reindexed;	/* # reclaimed reindexed triples */
508     size_t	uncollectable;		/* # uncollectable erased at last GC */
509     gen_t	last_gen;		/* Oldest generation at last-GC */
510     gen_t	last_reindex_gen;	/* Oldest reindexed at last GC */
511   } gc;
512 
513   struct
514   { simpleMutex	literal;		/* threaded access to literals */
515     simpleMutex misc;			/* general DB locks */
516     simpleMutex gc;			/* DB garbage collection lock */
517     simpleMutex duplicates;		/* Duplicate init lock */
518     simpleMutex erase;			/* Erase triples */
519     simpleMutex prefixes;		/* Prefix expansion */
520   } locks;
521 
522   struct
523   { snapshot *head;			/* head and tail of snapshot list */
524     snapshot *tail;
525     gen_t     keep;			/* generation to keep */
526   } snapshots;
527 
528   skiplist      literals;		/* (shared) literals */
529 } rdf_db;
530 
531 
532 		 /*******************************
533 		 *	       SETS		*
534 		 *******************************/
535 
536 #define CHUNKSIZE 4000				/* normally a page */
537 
538 typedef struct mchunk
539 { struct mchunk *next;
540   size_t used;
541   char buf[CHUNKSIZE];
542 } mchunk;
543 
544 typedef struct tmp_store
545 { mchunk     *chunks;
546   mchunk      store0;
547 } tmp_store;
548 
549 
550 		 /*******************************
551 		 *	     TRIPLE SET		*
552 		 *******************************/
553 
554 #define TRIPLESET_INITIAL_ENTRIES 4	/* often small */
555 
556 typedef struct triple_cell
557 { struct triple_cell *next;
558   triple *triple;
559 } triple_cell;
560 
561 typedef struct
562 { triple_cell **entries;		/* Hash entries */
563   size_t      size;			/* Hash-table size */
564   size_t      count;			/* # atoms stored */
565   tmp_store   store;			/* temporary store */
566   triple_cell *entries0[TRIPLESET_INITIAL_ENTRIES];
567 } tripleset;
568 
569 
570 		 /*******************************
571 		 *	    QUERY TYPES		*
572 		 *******************************/
573 
574 #include "buffer.h"
575 
576 #define LITERAL_EX_MAGIC 0x2b97e881
577 
578 typedef struct literal_ex
579 { literal  *literal;			/* the real literal */
580   atom_info atom;			/* prepared info on value */
581 #ifdef LITERAL_EX_MAGIC
582   long	    magic;
583 #endif
584 } literal_ex;
585 
586 
587 typedef struct search_state
588 { struct query *query;			/* Associated query */
589   rdf_db       *db;			/* our database */
590   term_t	subject;		/* Prolog term references */
591   term_t	object;
592   term_t	predicate;
593   term_t	src;
594   term_t	realpred;
595   unsigned	flags;			/* Misc flags controlling search */
596 					/* START memset() cleared area */
597   triple_walker cursor;			/* Pointer in triple DB */
598   triple	pattern;		/* Pattern triple */
599   atom_t	prefix;			/* prefix and like search */
600   int		alt_hash_cursor;	/* Index in alternative hashes */
601   int		has_literal_state;	/* Literal state is present */
602   literal      *literal_cursor;		/* pointer in current literal */
603   literal      *restart_lit;		/* for restarting literal search */
604   skiplist_enum literal_state;		/* Literal search state */
605   skiplist_enum restart_lit_state;	/* for restarting literal search */
606   predicate_cloud *p_cloud;		/* Searched predicate cloud */
607   triple       *prefetched;		/* Prefetched triple (retry) */
608 					/* END memset() cleared area */
609   literal_ex    lit_ex;			/* extended literal for fast compare */
610   tripleset	dup_answers;		/* possible duplicate answers */
611 } search_state;
612 
613 #include "query.h"
614 
615 
616 		 /*******************************
617 		 *	      BROADCASTS	*
618 		 *******************************/
619 
620 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
621 The ids form a mask. This must be kept consistent with monitor_mask/2 in
622 rdf_db.pl!
623 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
624 
625 typedef enum
626 { EV_ASSERT      = 0x0001,		/* triple */
627   EV_ASSERT_LOAD = 0x0002,		/* triple */
628   EV_RETRACT     = 0x0004,		/* triple */
629   EV_UPDATE      = 0x0008,		/* old, new */
630   EV_NEW_LITERAL = 0x0010,		/* literal */
631   EV_OLD_LITERAL = 0x0020,		/* literal */
632   EV_TRANSACTION = 0x0040,		/* id, begin/end */
633   EV_LOAD	 = 0x0080,		/* id, begin/end */
634   EV_CREATE_GRAPH= 0x0100,		/* graph name */
635   EV_RESET	 = 0x0200		/* reset */
636 } broadcast_id;
637 
638 
639 		 /*******************************
640 		 *	      FUNCTIONS		*
641 		 *******************************/
642 
643 COMMON(void *)	rdf_malloc(rdf_db *db, size_t size);
644 COMMON(void)	rdf_free(rdf_db *db, void *ptr, size_t size);
645 COMMON(int)	prelink_triple(rdf_db *db, triple *t, query *q);
646 COMMON(int)	link_triple(rdf_db *db, triple *t, query *q);
647 COMMON(int)	postlink_triple(rdf_db *db, triple *t, query *q);
648 COMMON(void)	erase_triple(rdf_db *db, triple *t, query *q);
649 COMMON(void)	add_triple_consequences(rdf_db *db, triple *t, query *q);
650 COMMON(void)	del_triple_consequences(rdf_db *db, triple *t, query *q);
651 COMMON(predicate *) lookup_predicate(rdf_db *db, atom_t name);
652 COMMON(rdf_db*)	rdf_current_db(void);
653 COMMON(int)	rdf_broadcast(broadcast_id id, void *a1, void *a2);
654 COMMON(int)	rdf_is_broadcasting(broadcast_id id);
655 COMMON(void)	consider_triple_rehash(rdf_db *db, size_t extra);
656 COMMON(int)	rdf_create_gc_thread(rdf_db *db);
657 COMMON(atom_t)  expand_prefix(rdf_db *db, atom_t alias, atom_t local);
658 
659 #include "error.h"
660 
661 #endif /*RDFDB_H_INCLUDED*/
662