Module database

Manipulation of database and arrays

Contents

Predicate


Top of this page Contents Index of this package LiLFeS Documents LiLFeS Home Page Tsujii laboratory

Predicate

db_open_env/3

Formatdb_open_env(+Home, +Info, -Handle) db_config(+Info)
Arguments
+Homestring directory name
+Info'ldbm:info_env'settings for this environment
-Handlehandle for this environment
+Info'ldbm:info_env'settings for this environment
NoteInfo is supposed to be a following feature structure;

(ldbm:info_env&
ldbm:mode\ +Mode& (optional)
ldbm:bdbm_page_size\ +Pagesize& (optional)
ldbm:bdbm_cache_size\ +Cachesize& (optional)
ldbm:flags\ +Flags)

+Mode:integerdirectory permission (optional, defalut value is the user defined file permission)
+Pagesize:integerthe page size in the Berkeley DB (optional, defalut value is 1024)
+Cachesize:integerthe cache size in the Berkeley DB (optional, defalut value is 32768)
+Flags:list of stringOptions for Berkeley DB. ["CREATE", "INIT_MPOOL", "PRIVATE"] should be specified if you are not familliar with BerkeleyDB. They are given in a list. If you open a file without specifying the environment, `default environment' is opened automatically. The default environment is opened with ["CREATE", "INIT_MPOOL", "PRIVATE"] flags.
db_open_env opens LiLDBM environment. db_config opens `default LiLDBM environment'. These are not necessary currently. They might be neccesarry if we develop multi-user processing functions or transaction.
> :- db_open_env("myenv", (ldbm:bdbm_page_size\ 1024 &
 ldbm:bdbm_cache_size\ 32768 &
 ldbm:flags\ ["CREATE", "INIT_MPOOL", "PRIVATE"]), $H).

db_open/4

Formatdb_open(+Pred) db_open(+File, +Info, +Pred) db_open(+Env, +file, +Info, +Pred)
Arguments
+Predpred name of DB
+Filestring file name
+Infoldbminfo_db :
+Predpred name of DB
+Envldbmhandle_env : Env specifies the environment that generates the file.
+Infoldbminfo_db :
+Predpred name of DB
NoteThe arguments of Pred are expressed as follows:
list up definition of keys and datas that has any dimension by marking off with comma. But, DB is dealt with predicate,so sum of parameters must be under 15.
key has two types:
key_integerInteger key.Feature "ARRAY_BASE\"(begin of subscript), "ARRAY_SIZE\"(number of subscript) must be defined.
key_inthashInteger hash key.Feature "ARRAY_SIZE\" can be defined.
key_floatfloat key
key_stringString key.It must be used like associative array.Feature "ARRAY_SIZE\" can be defined.
key_typetype key
key_fsFeature structure key.It must be used like associative array.Feature "ARRAY_SIZE\" can be defined.
And data has three types:
array_valuefeature structure
array_value_integerinteger
array_value_float float
array_value_stringstring
array_value_typetype

DB name must be declared as predicate(subtype of pred) in advance.And don't put any space between array name and "(".

Info is supposed to be the following feature structure;
(ldbm:info_db&
ldbm:mode\ +Mode& (optional)
ldbm:flags\ +Flags& (optional)
ldbm:type\ +Type& (optional)
ldbm:cache_size\ +Cache (optional))

+Mode: integer file permission (optional, defalut value is the user defined file permission)
+Type: string type of index structures, hash ("HASH") or b+tree ("BTREE"). (optional, default value is "BTREE").
+Flags: list of string Options for Berkeley DB. You should just specify "CREATE", if you are not familliar with BerkeleyDB. When "CREATE" is specified, a file is created if the specifed file does not exist, or a file is opened if the file exists. When "RDONLY" is specified, the file is opened as a read-only file. When "TRUNCATE" is specified, a file is created if the specified file does not exist, or a file is truncated if the file exists. "DIRTY_READ", "EXCL", or "NOMMAP" can also be specified. See Berkeley DB documents for further details. These options is specified as a list of string.
+Cache : integer Specifies the byte size of cache size of `LiLDBM cache', not `Berkeley DB cache'. The specified value must be more than 16,384 byte. The default value is 10 * 1048576 byte (=~ 10MB)
db_open/1 opens DB that keeps statistic values on memory. db_open/3 or db_open\4 opens DB on a file.
>  myarr <- [pred].
 >  :- db_open("mydata.db", (ldbm:flags\ ["CREATE"]),
 myarr(key_integer & ARRAY_BASE\0 & ARRAY_SIZE\2000,
 array_value)).
 >  myarr2 <- [pred].
 >  :- db_open(myarr2(key_inthash, array_value_string)).<BR><BR>
 >  myarr3 <- [pred].
 >  :- db_open(myarr3((key_integer & ARRAY_BASE\ 0 & ARRAY_SIZE\ 100),
 (key_integer & ARRAY_BASE\ 0 & ARRAY_SIZE\ 200),
 array_value_integer,
 array_value_integer,
 array_value_string)).
 The first example is array that that has integer as a key and keeps one feature structure on a file.                        
   The second example is array that has integer as a key and keeps a string on memory.
  The third example is array (which has 2nd dimension) of 100x200,which keeps two integer and one strings.It is similar with 
 struct arr1{
 int a;
 int b;
 char *c;
 }arr1[100][200];
 in C.

db_sync/1

Formatdb_sync(+Pred)
Arguments
+Predpred name of DB
The file DB is sync-ed.
>  myarr <- [pred].
 >  :- db_open("mydata.db", (ldbm:flags\ ["CREATE"]),
 myarr(key_integer & ARRAY_BASE\0 & ARRAY_SIZE\2000,
 array_value)).
 >  :- db_sync(myarr(_, _)).                        

db_close/1

Formatdb_close(+Pred)
Arguments
+Predpred name of DB
db_close closes the specified DB.
>  myarr <- [pred].
 >  :- db_open("mydata.db", (ldbm:flags\ ["CREATE"]),
 myarr(key_integer & ARRAY_BASE\0 & ARRAY_SIZE\2000,
 array_value)).
 >  :- db_close(myarr(_, _)).                        

db_find/2

Formatdb_find(+Pred) db_find(+Iter, +Pred)
Arguments
+Predpred name of DB
+Iterldbmiterator : the identifier for an entry
+Predpred name of DB
db_find/1 finds an entry specified keys in Pred. db_find/2 finds an entry specified by Iter.
>  myarr <- [pred].
 >  :- db_open("hoge.db", ldbm:flags\ ["CREATE"],
 myarr(key_inthash, array_value)).
 >  :- db_insert(my_arr(10, [1,2,3])).
 >  :- db_find(my_arr(10, X)), printAVM(X).
 >  :- db_first(my_arr(_, _), I), db_find(I, X), printAVM(X).

db_insert/1

Formatdb_insert(+Pred)
Arguments
+Predpred name of DB
db_insert/1 stores/overwrite an entry.
>  myarr <- [pred].
 >  :- db_open("hoge.db", ldbm:flags\ ["CREATE"],
 myarr(key_inthash, array_value)).
 >  :- db_insert(my_arr(10, [1,2,3])).
 >  :- db_find(my_arr(10, X)), printAVM(X).
 >  :- db_first(my_arr(_, _), I), db_find(I, X), printAVM(X).

db_delete/1

Formatdb_delete(+Pred)
Arguments
+Predpred name of DB
db_delete/1 deletes an entry specified by keys from the DB.
>  myarr <- [pred].
 >  :- db_open("hoge.db", ldbm:flags\ ["CREATE"],
 myarr(key_inthash, array_value)).
 >  :- db_insert(my_arr(10, [1,2,3])).
 >  :- db_delete(my_arr(10, _)).

db_clear/1

Formatdb_clear(+Pred)
Arguments
+Predpred name of DB
db_clear/1 deletes all entries in the DB.
>  myarr <- [pred].
 >  :- db_open("hoge.db", ldbm:flags\ ["CREATE"],
 myarr(key_inthash, array_value)).
 >  :- db_insert(my_arr(10, [1,2,3])).
 >  :- db_clear(my_arr(_, _)).

db_findall/2

Formatdb_findall(+Pred, -EntryList)
Arguments
+Predpred name of DB
-EntryLista list of all entries
db_findall/1 returns all entries in a list.
>  myarr <- [pred].
 >  :- db_declare("hoge.db", ldbm:flags\ ["CREATE"],
 myarr(key_inthash, array_value)).
 >  :- db_insert(my_arr(10, [1,2,3])).
 >  :- db_insert(my_arr(20, [4,5])).
 >  :- db_insert(my_arr(30, [6,7,8,9])).
 >  :- db_findall(my_arr(_, _), X), printAVM(X).

db_first/2

Formatdb_first(+Pred, -Iter)
Arguments
+Predpred name of DB
-Iterthe identifier of the first entry
db_first returs the identifier of the first entry in the DB.
>  :- db_declare("hoge.db", ldbm:flags\ ["CREATE"],
 myarr(key_inthash, array_value)).
 >  :- db_insert(my_arr(10, [1,2,3])).
 >  :- db_first(my_arr(_, _), I), db_find(I, X), printAVM(X).

db_last/2

Formatdb_last(+Pred, -Iter)
Arguments
+Predpred name of DB
-Iterthe identifier of the last entry
db_last returs the identifier of the last entry in the DB.
>  :- db_declare("hoge.db", ldbm:flags\ ["CREATE"],
 myarr(key_inthash, array_value)).
 >  :- db_insert(my_arr(10, [1,2,3])).
 >  :- db_last(my_arr(_, _), I), db_find(I, X), printAVM(X).

db_next/2

Formatdb_next(+Iter1, -Iter2)
Arguments
+Iter1the identifier of an entry
-Iter2the identifier of the next entry of Iter1
db_next returs the identifier of the next entry specified by Iter1. If there is no next entry, db_next fails.
>  myarr <- [pred].
 >  :- db_declare("hoge.db", ldbm:flags\ ["CREATE"],
 myarr(key_inthash, array_value)).
 >  :- db_insert(my_arr(10, [1,2,3])).
 >  :- db_insert(my_arr(30, [4,5,6,7])).
 >  :- db_first(my_arr(_, _), I), db_next(I, J), db_find(J, X), printAVM(X).

db_prev/2

Formatdb_prev(+Iter1, -Iter2)
Arguments
+Iter1the identifier of an entry
-Iter2the identifier of the previous entry of Iter1
db_prev returs the identifier of the previous entry specified by Iter1. If there is no previous entry, db_prev fails.
>  myarr <- [pred].
 >  :- db_declare("hoge.db", ldbm:flags\ ["CREATE"],
 myarr(key_inthash, array_value)).
 >  :- db_insert(my_arr(10, [1,2,3])).
 >  :- db_insert(my_arr(30, [4,5,6,7])).
 >  :- db_first(my_arr(_, _), I), db_prev(I, J), db_find(J, X), printAVM(X).

db_save/2

Formatdb_save(+FILE, +NAME)
Arguments
+FILEstring file name
+NAMEpred DB name
Save contents of DB into a file
 :- db_save("array1", arr1(_, _, _, _, _)).

db_load/2

Formatdb_load(+FILE, +NAME)
Arguments
+FILEstring file name
+NAMEpred DB name
Load contents of DB from a file
 :- db_load("array1", arr1(_, _, _, _, _)).

declare_array/1

Formatdeclare_array(+INFO)
Arguments
+INFOpred name of array(...)
How to express …… :
list up definition of keys and datas that has any dimension by marking off with comma. But,array is dealt with predicate,so sum of parameters must be under 15.
key has two types:
key_integerInteger key.Feature "ARRAY_BASE\"(begin of subscript), "ARRAY_SIZE\"(number of subscript) must be defined.
key_inthashInteger hash key.Feature "ARRAY_SIZE\" can be defined.
key_stringString key.It must be used like associative array.Feature "ARRAY_SIZE\" can be defined.
key_fsFeature structure key.It must be used like associative array.Feature "ARRAY_SIZE\" can be defined.
And data has three types:
array_valuefeature structure
array_value_integerinteger
array_value_stringstring
NoteArray name must be declared as predicate(subtype of pred) in advance.And don't put any space between array name and "(".
Make arrray that keeps statistic values.
> :- declare_array(arr1((key_integer & ARRAY_BASE\ 0 & ARRAY_SIZE\ 100),
 (key_integer & ARRAY_BASE\ 0 & ARRAY_SIZE\ 200),
 array_value_integer,
 array_value_integer,
 array_value_string)).
 > :- declare_array(arr2(key_string,
 array_value)).
  
  The first example is array (which has 2nd dimension) of 100x200,which keeps two integer and one strings.It is equal to 
 struct arr1{
 int a;
 int b;
 char *c;
 }arr1[100][200];
 in C.
  The second example is array that has string as key ans keeps one feature structure.

delete_array/1

Formatdelete_array(+NAME)
Arguments
+NAMEpred array name
Delete array NAME.
 :- delete_array(arr1(_, _, _, _, _)).

get_array/1

Formatget_array(+INFO)
Arguments
+INFOpred name of array(...)
See alsoset_array/1
Get value of array INFO.

set_array/1

Formatset_array(+INFO)
Arguments
+INFOpred name of array(...)
How to express …… :
Following keys and datas in declare_array,describe place for input and value.
See alsoget_array/1
Set value of array.
> :- set_array(arr1(3,4,200,55,"abc")).
 > :- set_array(arr2("foo", abc & F1\aa)).
 > ?- get_array(arr1(3,4,X,Y,Z)).
 X: 200
 Y: 55
 Z: "abc"
 > ?- get_array(arr2("foo",X)).
 X: |~abc  ~|
 |_F1:aa_|
  
  The first example is substitution of 200, 100, "abc" to the value of arr1[3][4].
  The second example is entry of feature structure abc & F1\aa to arr2 with key key of "foo".
  To refer to value of array,describe query with array name as predicate.

unset_array/1

Formatunset_array(+INFO)
Arguments
+INFOpred name of array(...)
How to express …… :
Specify all keys of the array
Unset value of array.
> :- unset_array(arr1(3,4,_,_,_)).
 > ?- get_array(arr1(3,4,X,Y,Z)).
 no

clear_array/1

Formatclear_array(+NAME)
Arguments
+NAMEpred array name
Clear contents of array NAME.
 :- clear_array(arr1(_, _, _, _, _)).

save_array/2

Formatsave_array(+FILE, +NAME)
Arguments
+FILEstring file name
+NAMEpred array name
Save contents of array into a file
 :- save_array("array1", arr1(_, _, _, _, _)).

load_array/2

Formatload_array(+FILE, +NAME)
Arguments
+FILEstring file name
+NAMEpred array name
Load contents of array from a file
 :- load_array("array1", arr1(_, _, _, _, _)).

Top of this page Contents Index of this package LiLFeS Documents LiLFeS Home Page Tsujii laboratory

This document is automatically created by lildoc on Fri Sep 24 14:13:58 2004