C Language Development Kit/Snippets/Database

From OptiWiki

Jump to: navigation, search

The database functions that will be described in this section can be used to create and use databases with the following properties.

Record size Fixed (All records must have same length)
Support of sorted and unsorted databases Both
Availability of search functions Yes
Availability of sort functions Yes
Possibility to add an index file to the database Yes

Contents

Sources of all database functions

To be able to use the database functions, include the following header file and source file in your project.

Header file database.h (source)
Source file database.c (source)

Creating, opening and closing a database

The following functions can be used to create, open and close a database.

Database properties

The following functions return general properties and information of the current state of the database.

Read, write and delete records of a database

The following functions make it possible to read, write, delete and jump to every desired record of the database.

Searching records in a database

The following functions can be used to search records in a database. Use BinarySearch() for sorted databases and use LineairSearch() for unsorted databases.

  • BinarySearch() Searches in database for a searchkey. Works only on sorted databases.
  • LineairSearch() Searches database for a searchkey. Works on sorted and not sorted databases, but is slow.

Sorting records of a database

Depending on whether the database is already almost sorted or not and the amount of resources that may be used, the following sorting functions are available.

  • InsertionSort() Sorts database with insertion sort algorithm. Fast for almost sorted databases.
  • HeapSort() Sorts database with heapsort algorithm. Good performance on not sorted databases.
  • QuickSort() Sorts database with quicksort algorithm. Very good performance on not sorted databases.

Creating and using index files

Sorted index files can be added to a database to be able to quickly search in unsorted databases that may not be sorted. It is also possible to add multiple sorted index to a single database to quickly search for different aspects of a record.

Views
Personal tools