XMMS2
index.c File Reference
#include "s4_priv.h"
#include <stdlib.h>
#include <string.h>

Functions

s4_index_data_t * _index_create_data ()
void _index_free_data (s4_index_data_t *data)
s4_index_t * _index_get_a (s4_t *s4, const char *key, int create)
 Gets the a-index associated with key.
s4_index_t * _index_get_b (s4_t *s4, const char *key)
 Gets the b-index associated with key.
GList * _index_get_all_a (s4_t *s4)
 Gets all a-indexes.
GList * _index_get_all_b (s4_t *s4)
 Gets all b-indexes.
s4_index_t * _index_create ()
 Creates a new index.
int _index_add (s4_t *s4, const char *key, s4_index_t *index)
 Adds an index to a database.
int _index_insert (s4_index_t *index, const s4_val_t *val, void *new_data)
 Inserts a new value-data pair into the index.
int _index_delete (s4_index_t *index, const s4_val_t *val, void *data)
 Removes a value-data pair from the index.
GList * _index_search (s4_index_t *index, index_function_t func, void *func_data)
 Searches an index.
GList * _index_lsearch (s4_index_t *index, index_function_t func, void *func_data)
 Searches an index using a linear search.
void _index_free (s4_index_t *index)
 Frees an index.
int _index_lock_shared (s4_index_t *index, s4_transaction_t *trans)
int _index_lock_exclusive (s4_index_t *index, s4_transaction_t *trans)

Function Documentation

◆ _index_add()

int _index_add ( s4_t * s4,
const char * key,
s4_index_t * index )

Adds an index to a database.

Parameters
s4The database to add the index to
keyThe key to associate the index with
indexThe index to insert
Returns
0 if the key already has an index, non-zero otherwise

Referenced by _index_add(), and s4_open().

◆ _index_create()

s4_index_t * _index_create ( void )

Creates a new index.

Returns
A new index

Referenced by _index_create(), _index_get_a(), and s4_open().

◆ _index_create_data()

s4_index_data_t * _index_create_data ( void )

Referenced by _index_create_data(), and _reread_file().

◆ _index_delete()

int _index_delete ( s4_index_t * index,
const s4_val_t * val,
void * data )

Removes a value-data pair from the index.

Parameters
indexThe index to remove from
valThe value to remove
dataThe data to remove
Returns
0 if the value-data pair is not found, 1 otherwise

Referenced by _index_delete(), and _s4_del().

◆ _index_free()

void _index_free ( s4_index_t * index)

Frees an index.

The values and data is NOT freed

Parameters
indexThe index to free

Referenced by _index_create_data(), and _index_free().

◆ _index_free_data()

void _index_free_data ( s4_index_data_t * data)

Referenced by _index_free_data(), and _reread_file().

◆ _index_get_a()

s4_index_t * _index_get_a ( s4_t * s4,
const char * key,
int create )

Gets the a-index associated with key.

A a-index is used to lookup entries by the a-value. If an index has not yet been created for this key and create is non-zero, one will be created and returned.

Parameters
s4The database to look for the index in
keyThe key the index should be indexing
createCreates the index if it does not exist
Returns
The index, or NULL if it does not exist and create is 0.

Referenced by _index_get_a(), _s4_add(), _s4_add_internal(), _s4_del(), and _s4_query().

◆ _index_get_all_a()

GList * _index_get_all_a ( s4_t * s4)

Gets all a-indexes.

Parameters
s4The database to get the index of.
Returns
A list of indexes.

Referenced by _free_relations(), _index_get_all_a(), and _s4_query().

◆ _index_get_all_b()

GList * _index_get_all_b ( s4_t * s4)

Gets all b-indexes.

Parameters
s4The database to get the index of.
Returns
A list of indexes.

Referenced by _index_get_all_b().

◆ _index_get_b()

s4_index_t * _index_get_b ( s4_t * s4,
const char * key )

Gets the b-index associated with key.

A b-index is used to lookup entries by the b-value.

Parameters
s4The database to look for the index in
keyThe key the index should be indexing
Returns
The index, or NULL if it is not found

Referenced by _index_get_b(), _s4_add(), _s4_add_internal(), _s4_del(), and _s4_query().

◆ _index_insert()

int _index_insert ( s4_index_t * index,
const s4_val_t * val,
void * new_data )

Inserts a new value-data pair into the index.

Parameters
indexThe index to insert into
valThe value to associate the data with
new_dataThe data
Returns
1

Referenced by _index_insert(), _s4_add(), and _s4_add_internal().

◆ _index_lock_exclusive()

int _index_lock_exclusive ( s4_index_t * index,
s4_transaction_t * trans )

◆ _index_lock_shared()

int _index_lock_shared ( s4_index_t * index,
s4_transaction_t * trans )

◆ _index_lsearch()

GList * _index_lsearch ( s4_index_t * index,
index_function_t func,
void * func_data )

Searches an index using a linear search.

Parameters
indexThe index to search
funcThe function to use when searching. It should return 0 if the value matches, -1 if the value is too small and 1 if the value is too big,
func_dataData passed as the second argument to func
Returns
A GList where list->data is the data found matching

Referenced by _index_lsearch(), and _s4_query().

◆ _index_search()

GList * _index_search ( s4_index_t * index,
index_function_t func,
void * func_data )

Searches an index.

Parameters
indexThe index to search
funcThe function to use when searching. It must be monotonic, It should return 0 if the value matches, -1 if the value is too small and 1 if the value is too big,
func_dataData passed as the second argument to func
Returns
A GList where list->data is the data found matching

Referenced by _free_relations(), _index_search(), _s4_add(), _s4_add_internal(), _s4_del(), and _s4_query().