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

Weighted Items

Detailed Description

A weighted collection item with an associated weight value.

Introduction

A WeightedItem represents a value retrieved from the dataset together with a weight indicating the proportion or confidence of this value (out of 65535). Used for profile-level weighting (from profile groups) where the weight indicates the proportion of the matched IP range attributable to this profile, or for value-level weighting where the weight is stored in the Value record.

List Management

WeightedItemList provides a resizable array of WeightedItem structures with functions for initialization, release, extension, and adding items.

Collaboration diagram for Weighted Items:

Structs

struct  fiftyoneDegreesWeightedItem
 A weighted collection item. More...
struct  fiftyoneDegreesWeightedItemList
 A resizable list of weighted items. More...

Macros

#define FIFTYONE_DEGREES_WEIGHTED_ITEM_LIST_RESIZE_FACTOR   2
 Default resize factor for WeightedItemList when extending capacity.
#define FIFTYONE_DEGREES_WEIGHTED_ITEM_LIST_DEFAULT_LOAD_FACTOR   4
 Default load factor for WeightedItemList initial capacity calculation.
#define FIFTYONE_DEGREES_WEIGHTED_ITEM_MAX_WEIGHT   ((uint32_t)(((uint32_t)65535)*((uint32_t)65535)))
 Max value for WeightedItem.rawWeighting.

Functions

void fiftyoneDegreesWeightedItemListInit (fiftyoneDegreesWeightedItemList *list, uint32_t initialCapacity, float loadFactor)
 Initializes a weighted item list with the specified initial capacity.
void fiftyoneDegreesWeightedItemListRelease (fiftyoneDegreesWeightedItemList *list)
 Releases all collection items in the list and resets the count to zero.
void fiftyoneDegreesWeightedItemListFree (fiftyoneDegreesWeightedItemList *list)
 Frees the items array and resets the list to empty state.
void fiftyoneDegreesWeightedItemListExtend (fiftyoneDegreesWeightedItemList *list, uint32_t newCapacity, fiftyoneDegreesException *exception)
 Extends the capacity of the list to the new capacity.
void fiftyoneDegreesWeightedItemListAdd (fiftyoneDegreesWeightedItemList *list, const fiftyoneDegreesWeightedItem *item, fiftyoneDegreesException *exception)
 Adds a copy of the item to the list, extending capacity if needed based on the load factor.

Function Documentation

◆ fiftyoneDegreesWeightedItemListAdd()

void fiftyoneDegreesWeightedItemListAdd ( fiftyoneDegreesWeightedItemList * list,
const fiftyoneDegreesWeightedItem * item,
fiftyoneDegreesException * exception )

Adds a copy of the item to the list, extending capacity if needed based on the load factor.

Parameters
listpointer to the list to add to
itempointer to the item to copy into the list
exceptionpointer to an exception data structure to be used if an exception occurs. See exceptions.h.

◆ fiftyoneDegreesWeightedItemListExtend()

void fiftyoneDegreesWeightedItemListExtend ( fiftyoneDegreesWeightedItemList * list,
uint32_t newCapacity,
fiftyoneDegreesException * exception )

Extends the capacity of the list to the new capacity.

Parameters
listpointer to the list to extend
newCapacitythe new capacity (must be greater than current)
exceptionpointer to an exception data structure to be used if an exception occurs. See exceptions.h.

◆ fiftyoneDegreesWeightedItemListFree()

void fiftyoneDegreesWeightedItemListFree ( fiftyoneDegreesWeightedItemList * list)

Frees the items array and resets the list to empty state.

Releases all items first.

Parameters
listpointer to the list to free

◆ fiftyoneDegreesWeightedItemListInit()

void fiftyoneDegreesWeightedItemListInit ( fiftyoneDegreesWeightedItemList * list,
uint32_t initialCapacity,
float loadFactor )

Initializes a weighted item list with the specified initial capacity.

Parameters
listpointer to the list to initialize
initialCapacitythe initial capacity to allocate
loadFactorthe load factor threshold for auto-extension (0.0-1.0)

◆ fiftyoneDegreesWeightedItemListRelease()

void fiftyoneDegreesWeightedItemListRelease ( fiftyoneDegreesWeightedItemList * list)

Releases all collection items in the list and resets the count to zero.

Does not free the items array itself. Each item's collection is obtained from the item itself.

Parameters
listpointer to the list to release