\r\n

51Degrees Device Detection C/C++  4.5

A device detection library that is used natively or by 51Degrees products

Indices

Detailed Description

A look up structure for profile and property index to the first value associated with the property and profile.

Introduction

Data sets relate profiles to the values associated with them. Values are associated with properties. The values associated with a profile are ordered in ascending order of property. Therefore when a request is made to obtain the value for a property and profile the values needed to be searched using a binary search to find a value related to the property. Then the list of prior values is checked until the first value for the property is found.

The indices methods provide common functionality to create a structure that directly relates profile ids and required property indexes to the first value index thus increasing the efficiency of retrieving values.

It is expected these methods will be used during data set initialization.

Structure

A sparse array of profile ids and required property indexes is used. Whilst this consumes more linear memory than a binary tree or other structure it is extremely fast to retrieve values from. As the difference between the lowest and highest profile id is relatively small the memory associated with absent profile ids is considered justifiable considering the performance benefit. A further optimization is to use the required property index rather than the index of all possible properties contained in the data set. In most use cases the caller only requires a sub set of properties to be available for retrieval.

Create

fiftyoneDegreesIndicesPropertyProfileCreate should be called once the data set is initialized with the required data structures. Memory is allocated by the method and a pointer to the index data structure is returned. The caller is not expected to use the returned data structure directly.

Some working memory is allocated during the indexing process. Therefore this method must be called before a freeze on allocating new memory is required.

Free

fiftyoneDegreesIndicesPropertyProfileFree is used to free the memory used by the index returned from Create. Must be called during the freeing of the related data set.

Lookup

fiftyoneDegreesIndicesPropertyProfileLookup is used to return the index in the values associated with the profile for the profile id and the required property index.

Collaboration diagram for Indices:

Structs

struct  fiftyoneDegreesIndicesPropertyProfile
Maps the profile index and the property index to the first value index of the profile for the property. More...

Functions

fiftyoneDegreesIndicesPropertyProfile *  fiftyoneDegreesIndicesPropertyProfileCreate (fiftyoneDegreesCollection *profiles, fiftyoneDegreesCollection *profileOffsets, fiftyoneDegreesPropertiesAvailable *available, fiftyoneDegreesCollection *values, fiftyoneDegreesException *exception)
Create an index for the profiles, available properties, and values provided such that given the index to a property and profile the index of the first value can be returned by calling fiftyoneDegreesIndicesPropertyProfileLookup. More...
void  fiftyoneDegreesIndicesPropertyProfileFree (fiftyoneDegreesIndicesPropertyProfile *index)
Frees an index previously created by fiftyoneDegreesIndicesPropertyProfileCreate. More...
uint32_t  fiftyoneDegreesIndicesPropertyProfileLookup (fiftyoneDegreesIndicesPropertyProfile *index, uint32_t profileId, uint32_t availablePropertyIndex)
For a given profile id and available property index returns the first value index, or null if a first index can not be determined from the index. More...

Function Documentation

◆ fiftyoneDegreesIndicesPropertyProfileCreate()

fiftyoneDegreesIndicesPropertyProfile* fiftyoneDegreesIndicesPropertyProfileCreate ( fiftyoneDegreesCollection *   profiles,
fiftyoneDegreesCollection *   profileOffsets,
fiftyoneDegreesPropertiesAvailable *   available,
fiftyoneDegreesCollection *   values,
fiftyoneDegreesException *   exception  
)

Create an index for the profiles, available properties, and values provided such that given the index to a property and profile the index of the first value can be returned by calling fiftyoneDegreesIndicesPropertyProfileLookup.

Parameters
profiles - collection of variable sized profiles to be indexed
profileOffsets - collection of fixed offsets to profiles to be indexed
available - properties provided by the caller
values - collection to be indexed
exception - pointer to an exception data structure to be used if an exception occurs. See exceptions.h
Returns
pointer to the index memory structure

◆ fiftyoneDegreesIndicesPropertyProfileFree()

void fiftyoneDegreesIndicesPropertyProfileFree ( fiftyoneDegreesIndicesPropertyProfile *   index )

Frees an index previously created by fiftyoneDegreesIndicesPropertyProfileCreate.

Parameters
index - to be freed

◆ fiftyoneDegreesIndicesPropertyProfileLookup()

uint32_t fiftyoneDegreesIndicesPropertyProfileLookup ( fiftyoneDegreesIndicesPropertyProfile *   index,
uint32_t   profileId,
uint32_t   availablePropertyIndex  
)

For a given profile id and available property index returns the first value index, or null if a first index can not be determined from the index.

The indexes relate to the collections for profiles, properties, and values provided to the fiftyoneDegreesIndicesPropertyProfileCreate method when the index was created. The availablePropertyIndex is not the index of all possible properties, but the index of the ones the data set was created expecting to return.

Parameters
index - from fiftyoneDegreesIndicesPropertyProfileCreate to use
profileId - the values need to relate to
availablePropertyIndex - in the list of required properties
Returns
the index in the list of values for the profile for the first value associated with the property
On This Page