XMMS2
Functions
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. More...
 
s4_index_t_index_get_b (s4_t *s4, const char *key)
 Gets the b-index associated with key. More...
 
GList * _index_get_all_a (s4_t *s4)
 Gets all a-indexes. More...
 
GList * _index_get_all_b (s4_t *s4)
 Gets all b-indexes. More...
 
s4_index_t_index_create ()
 Creates a new index. More...
 
int _index_add (s4_t *s4, const char *key, s4_index_t *index)
 Adds an index to a database. More...
 
int _index_insert (s4_index_t *index, const s4_val_t *val, void *new_data)
 Inserts a new value-data pair into the index. More...
 
int _index_delete (s4_index_t *index, const s4_val_t *val, void *data)
 Removes a value-data pair from the index. More...
 
GList * _index_search (s4_index_t *index, index_function_t func, void *func_data)
 Searches an index. More...
 
GList * _index_lsearch (s4_index_t *index, index_function_t func, void *func_data)
 Searches an index using a linear search. More...
 
void _index_free (s4_index_t *index)
 Frees an index. More...
 
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

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 s4_open().

s4_index_t* _index_create ( void  )

Creates a new index.

Returns
A new index

Referenced by _index_get_a(), and s4_open().

s4_index_data_t* _index_create_data ( void  )

Referenced by _reread_file().

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 _s4_del().

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().

void _index_free_data ( s4_index_data_t data)

Referenced by _reread_file().

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 _s4_add(), _s4_add_internal(), _s4_del(), and _s4_query().

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(), and _s4_query().

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.
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 _s4_add(), _s4_add_internal(), _s4_del(), and _s4_query().

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 _s4_add(), and _s4_add_internal().

int _index_lock_exclusive ( s4_index_t index,
s4_transaction_t trans 
)

Referenced by _s4_add(), and _s4_del().

int _index_lock_shared ( s4_index_t index,
s4_transaction_t trans 
)

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

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 _s4_query().

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(), _s4_add(), _s4_add_internal(), _s4_del(), and _s4_query().