YAP 7.1.0
udi.h
1/*
2 * This file is part of the YAP Prolog
3 *
4 * User Defined Indexing was developed by:
5 * David Vaz <davidvaz@dcc.fc.up.pt>
6 * Vitor Santos Costa <vsc@dcc.fc.up.pt>
7 *
8 * UDI Indexing Interface:
9 *
10 * Each new indexing mechanism should register it self by filling up a
11 * UdiControlBlock and calling Yap_UdiRegister(UdiControlBlock).
12 *
13 * UdiControlBlock has the main declaration that triggers the
14 * indexing structure as well as the pointers to the needed functions
15 * called at the appropriate times.
16 *
17 * For now each indexing structure only works with a single argument
18 * even when multiple arguments are indexed with the same struture.
19 *
20 * TODO: think of alternative ways of support both cases, e.g. a rtree
21 * does not benefit from multiple rtree indexing, but a hash table do
22 */
23
24/* This is called upon udi mode spec call, and the purpose is to allow
25 * the indexing struture to initialize itself.
26 * Should return the need opaque struture to be used in future calls
27 *
28 * arg is used to track the specific call, on multiple indexing with the
29 * same struture
30 */
31typedef void * (* Yap_UdiInit)
32 (YAP_Term spec,
33 int arg, /* argument regarding this call */
34 int arity);
35
36/* Upon each assert the struture insert method is called to perform
37 * its work
38 */
39typedef void * (* Yap_UdiInsert)
40 (void *control, /* indexing structure opaque handle */
41 YAP_Term term, /* asserted argument */
42 int arg, /* argument regarding this call */
43 void *data); /* value to return on search */
44
45/* Callback for each value found in a search
46 * if it returns FALSE the search should be immediately aborted
47 */
48typedef int (* Yap_UdiCallback)
49 (void *key, /* index key */
50 void *data, /* data */
51 void *arg); /* auxiliary data to callback */
52
53/* Called upon search
54 *
55 * If there is any search to do with this structure should return >= 0
56 * corresponding to the values found
57 *
58 * returns -1 if there is nothing to search with this indexing structure
59 * e.g. a Variable as argument
60 */
61typedef int (* Yap_UdiSearch)
62 (void * control, /* indexing structure opaque handle */
63 int arg, /* argument regarding this call */
64 Yap_UdiCallback f, /* callback on each found value */
65 void *args); /* auxiliary data to callback */
66
67/* Called upon abolish of the term
68 * to allow for a clean destroy of the indexing structures
69 */
70typedef int (* Yap_UdiDestroy)
71 (void * control);
72
73/*
74 * Main structure used in UDI
75 */
76typedef struct udi_control_block {
77 YAP_Atom decl; //atom that triggers this indexing structure
78 Yap_UdiInit init;
79 Yap_UdiInsert insert;
80 Yap_UdiSearch search;
81 Yap_UdiDestroy destroy;
83
84/* Register a new indexing structure */
85void Yap_UdiRegister(UdiControlBlock);