Module KeyDB

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.

Remark: This library has been revised to the library KeyDatabase. Thus, it might not be further supported in the future.

Author: Bernd Brassel, Michael Hanus

Version: January 2006

Summary of exported operations:

existsDBKey :: (Int -> a -> Dynamic) -> Int -> IO Bool   
Exists an entry with a given key in the database?
allDBKeys :: (Int -> a -> Dynamic) -> IO [Int]   
Returns all keys of entries in the database.
getDBInfo :: (Int -> a -> Dynamic) -> Int -> IO 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] -> IO [a]   
Gets the information about a list of entries in the database.
deleteDBEntry :: (Int -> a -> Dynamic) -> Int -> IO ()   
Deletes an entry with a given key in the database.
updateDBEntry :: (Int -> a -> Dynamic) -> Int -> a -> IO ()   
Overwrites an existing entry in the database.
newDBEntry :: (Int -> a -> Dynamic) -> a -> IO Int   
Stores a new entry in the database and return the key of the new entry.
cleanDB :: (Int -> a -> Dynamic) -> IO ()   
Deletes all entries in the database.

Exported operations:

existsDBKey :: (Int -> a -> Dynamic) -> Int -> IO 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) -> IO [Int]   

Returns all keys of entries in the database.

getDBInfo :: (Int -> a -> Dynamic) -> Int -> IO 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] -> IO [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 -> IO ()   

Deletes an entry with a given key in the database.

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

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

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 -> IO 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

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

Deletes all entries in the database.