Module KeyDatabase

This module provides a general interface for databases (persistent predicates) where each entry consists of a key and an info part. The key is an integer and the info is arbitrary. All functions are parameterized with a dynamic predicate that takes an integer key as a first parameter.

Author: Bernd Brassel, Michael Hanus

Version: August 2011

Summary of exported operations:

existsDBKey :: (Int -> a -> Dynamic) -> Int -> Query Bool   
Exists an entry with a given key in the database?
allDBKeys :: (Int -> a -> Dynamic) -> Query [Int]   
Query that returns all keys of entries in the database.
allDBInfos :: (Int -> a -> Dynamic) -> Query [a]   
Query that returns all infos of entries in the database.
allDBKeyInfos :: (Int -> a -> Dynamic) -> Query [(Int,a)]   
Query that returns all key/info pairs of the database.
getDBInfo :: (Int -> a -> Dynamic) -> Int -> Query (Maybe a)   
Gets the information about an entry in the database.
index :: a -> [a] -> Int   
compute the position of an entry in a list fail, if given entry is not an element.
sortByIndex :: [(Int,a)] -> [a]   
Sorts a given list by associated index .
groupByIndex :: [(Int,a)] -> [[a]]   
Sorts a given list by associated index and group for identical index.
getDBInfos :: (Int -> a -> Dynamic) -> [Int] -> Query (Maybe [a])   
Gets the information about a list of entries in the database.
deleteDBEntry :: (Int -> a -> Dynamic) -> Int -> Transaction ()   
Deletes an entry with a given key in the database.
deleteDBEntries :: (Int -> a -> Dynamic) -> [Int] -> Transaction ()   
Deletes all entries with the given keys in the database.
updateDBEntry :: (Int -> a -> Dynamic) -> Int -> a -> Transaction ()   
Overwrites an existing entry in the database.
newDBEntry :: (Int -> a -> Dynamic) -> a -> Transaction Int   
Stores a new entry in the database and return the key of the new entry.
newDBKeyEntry :: (Int -> a -> Dynamic) -> Int -> a -> Transaction ()   
Stores a new entry in the database under a given key.
cleanDB :: (Int -> a -> Dynamic) -> Transaction ()   
Deletes all entries in the database.

Exported operations:

existsDBKey :: (Int -> a -> Dynamic) -> Int -> Query Bool   

Exists an entry with a given key in the database?

Example call:
(existsDBKey db key)
Parameters:
  • db : the database (a dynamic predicate)
  • key : a key (an integer)

allDBKeys :: (Int -> a -> Dynamic) -> Query [Int]   

Query that returns all keys of entries in the database.

allDBInfos :: (Int -> a -> Dynamic) -> Query [a]   

Query that returns all infos of entries in the database.

allDBKeyInfos :: (Int -> a -> Dynamic) -> Query [(Int,a)]   

Query that returns all key/info pairs of the database.

getDBInfo :: (Int -> a -> Dynamic) -> Int -> Query (Maybe a)   

Gets the information about an entry in the database.

Example call:
(getDBInfo db key)
Parameters:
  • db : the database (a dynamic predicate)
  • key : the key of the entry (an integer)

index :: a -> [a] -> Int   

compute the position of an entry in a list fail, if given entry is not an element.

Example call:
(index x xs)
Parameters:
  • x : the entry searched for
  • xs : the list to search in

sortByIndex :: [(Int,a)] -> [a]   

Sorts a given list by associated index .

groupByIndex :: [(Int,a)] -> [[a]]   

Sorts a given list by associated index and group for identical index. Empty lists are added for missing indexes

getDBInfos :: (Int -> a -> Dynamic) -> [Int] -> Query (Maybe [a])   

Gets the information about a list of entries in the database.

Example call:
(getDBInfos db keys)
Parameters:
  • db : the database (a dynamic predicate)
  • keys : the list of keys of the entry (integers)

deleteDBEntry :: (Int -> a -> Dynamic) -> Int -> Transaction ()   

Deletes an entry with a given key in the database. No error is raised if the given key does not exist.

Example call:
(deleteDBEntry db key)
Parameters:
  • db : the database (a dynamic predicate)
  • key : the key of the entry (an integer)

deleteDBEntries :: (Int -> a -> Dynamic) -> [Int] -> Transaction ()   

Deletes all entries with the given keys in the database. No error is raised if some of the given keys does not exist.

Example call:
(deleteDBEntries db keys)
Parameters:
  • db : the database (a dynamic predicate)
  • keys : the list of keys of the entries to be deleted

updateDBEntry :: (Int -> a -> Dynamic) -> Int -> a -> Transaction ()   

Overwrites an existing entry in the database.

Example call:
(updateDBEntry db key info)
Parameters:
  • db : the database (a dynamic predicate)
  • key : the key of the entry (an integer)
  • info : the information to be stored in the updated entry

newDBEntry :: (Int -> a -> Dynamic) -> a -> Transaction Int   

Stores a new entry in the database and return the key of the new entry.

Example call:
(newDBEntry db info)
Parameters:
  • db : the database (a dynamic predicate)
  • info : the information to be stored in the new entry

newDBKeyEntry :: (Int -> a -> Dynamic) -> Int -> a -> Transaction ()   

Stores a new entry in the database under a given key. The transaction fails if the key already exists.

Example call:
(newDBKeyEntry db key info)
Parameters:
  • db : the database (a dynamic predicate)
  • key : the key of the new entry (an integer)
  • info : the information to be stored in the new entry

cleanDB :: (Int -> a -> Dynamic) -> Transaction ()   

Deletes all entries in the database.