xchange v0.9
Structured data exchange for C/C++
|
Macros | |
#define | __XCHANGE_INTERNAL_API__ |
Use internal definitions. | |
Functions | |
XLookupTable * | xAllocLookup (unsigned int size) |
XLookupTable * | xCreateLookup (const XStructure *s, boolean recursive) |
void | xDestroyLookup (XLookupTable *tab) |
long | xLookupCount (const XLookupTable *tab) |
XField * | xLookupField (const XLookupTable *tab, const char *id) |
int | xLookupPut (XLookupTable *tab, const char *prefix, const XField *field, XField **oldValue) |
int | xLookupPutAll (XLookupTable *tab, const char *prefix, const XStructure *s, boolean recursive) |
XField * | xLookupRemove (XLookupTable *tab, const char *id) |
int | xLookupRemoveAll (XLookupTable *tab, const char *prefix, const XStructure *s, boolean recursive) |
Lookup table for faster field access in large fixed-layout structures.
XLookupTable * xAllocLookup | ( | unsigned int | size | ) |
Allocates a new lookup with the specified hash size. The hash size should correspond to the number of elements stored in the lookup. If it's larger or roughtly equal to the number of elements to be stored, then the lookup time will stay approximately constant with the number of elements. If the size is much smaller than the number of elements N stored, then the lookup time will scale as O(N/size) typically.
size | The number of hash bins to allocate |
References FALSE, XLookupTable::priv, and x_error().
XLookupTable * xCreateLookup | ( | const XStructure * | s, |
boolean | recursive | ||
) |
Creates a fast name lookup table for the fields of structure, with or without including fields of embedded substructures also. For structures with a large number of fields, such a lookup can significantly improve access times for retrieving specific fields from a structure. However, the lookup will not track fields added or removed after its creation, and so it is suited for accessing structures with a fixed layout only.
Since the lookup table contains references to the structure, you should not destroy the structure as long as the lookup table is used.
Once the lookup table is no longer used, the caller should explicitly destroy it with xDestroyLookup()
s | Pointer to a structure, for which to create a field lookup. |
recursive | Whether to include fields from substructures recursively in the lookup. |
References x_error(), x_trace_null(), xAllocLookup(), xCountFields(), and xDeepCountFields().
void xDestroyLookup | ( | XLookupTable * | tab | ) |
Destroys a lookup table, freeing up it's in-memory resources.
tab | Pointer to the lookup table to destroy. |
References XLookupTable::priv.
long xLookupCount | ( | const XLookupTable * | tab | ) |
Returns the number of fields in the lookup table.
tab | Pointer to the lookup table |
References XLookupTable::priv.
XField * xLookupField | ( | const XLookupTable * | tab, |
const char * | id | ||
) |
Returns a named field from a lookup table. When retriving a large number (hundreds or more) fields by name from very large structures, this methods of locating the relevant data can be significantly faster than the xGetField() / xGetSubstruct() approach.
Note however, that preparing the lookup table has significant O(N) computational cost also, whereas retrieving M fields with xGetField() / xGetSubstruct() have costs that scale O(N×M). Therefore, a lookup table is practical only if you are going to use it repeatedly, many times over. As a rule of thumb, lookups may have the advantage if accessing fields in a structure by name hundreds of times, or more.
tab | Pointer to the lookup table |
id | The aggregate ID of the field to find. |
References XLookupTable::priv, and x_error().
int xLookupPut | ( | XLookupTable * | tab, |
const char * | prefix, | ||
const XField * | field, | ||
XField ** | oldValue | ||
) |
Puts a field into the lookup table with the specified aggregate ID prefix. For example, if the prefix is "system:subsystem", and the field's name is "property", then the field will be available as "system:subsystem:property" in the lookup.
tab | Pointer to a lookup table |
prefix | The aggregate ID prefix before the field's name, not including a separator |
field | The field |
oldValue | (optional) pointer to a buffer in which to return the old field value (if any) stored under the same name. It may be NULL if not needed. |
References XLookupTable::priv, x_error(), X_FAILURE, and X_NULL.
int xLookupPutAll | ( | XLookupTable * | tab, |
const char * | prefix, | ||
const XStructure * | s, | ||
boolean | recursive | ||
) |
Puts all fields from a structure into the lookup table with the specified aggregate ID prefix, with or without including embedded substructures. For example, if the prefix is "system:subsystem", and a field's name is "property", then that field will be available as "system:subsystem:property" in the lookup.
tab | Pointer to a lookup table |
prefix | The aggregate ID prefix before the field's name, not including a separator |
s | The structure |
recursive | Whether to include fields in all substructures recursively also. |
References XLookupTable::priv, x_error(), X_FAILURE, and X_NULL.
XField * xLookupRemove | ( | XLookupTable * | tab, |
const char * | id | ||
) |
Removes a field from a lookup table.
tab | Pointer to the lookup table |
id | The aggregate ID of the field as stored in the lookup |
References XLookupTable::priv, x_error(), and X_NULL.
int xLookupRemoveAll | ( | XLookupTable * | tab, |
const char * | prefix, | ||
const XStructure * | s, | ||
boolean | recursive | ||
) |
Removes all fields of a structure from the lookup table with the specified aggregate ID prefix, with or without including embedded substructures. For example, if the prefix is "system:subsystem", and a field's name is "property", then the field referred to as "system:subsystem:property" in the lookup is affected.
tab | Pointer to a lookup table |
prefix | The aggregate ID prefix before the field's name, not including a separator |
s | The structure |
recursive | Whether to include fields in all substructures recursively also. |
References XLookupTable::priv, x_error(), X_FAILURE, and X_NULL.