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

weightedItem.h

1/* *********************************************************************
2 * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3 * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House,
4 * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
5 *
6 * This Original Work is licensed under the European Union Public Licence
7 * (EUPL) v.1.2 and is subject to its terms as set out below.
8 *
9 * If a copy of the EUPL was not distributed with this file, You can obtain
10 * one at https://opensource.org/licenses/EUPL-1.2.
11 *
12 * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13 * amended by the European Commission) shall be deemed incompatible for
14 * the purposes of the Work and the provisions of the compatibility
15 * clause in Article 5 of the EUPL shall not apply.
16 *
17 * If using the Work as, or as part of, a network application, by
18 * including the attribution notice(s) required under Article 5 of the EUPL
19 * in the end user terms of the application under an appropriate heading,
20 * such notice(s) shall fulfill the requirements of that article.
21 * ********************************************************************* */
22
23#ifndef FIFTYONE_DEGREES_WEIGHTED_ITEM_H_INCLUDED
24#define FIFTYONE_DEGREES_WEIGHTED_ITEM_H_INCLUDED
25
26#ifdef FIFTYONE_DEGREES_IPI_SYMBOLS
27#include "ipiSymbols.h"
28#endif
29
51
52#include <stdint.h>
53#include "collection.h"
54#include "common.h"
55#include "status.h"
56#include "exceptions.h"
57
61#define FIFTYONE_DEGREES_WEIGHTED_ITEM_LIST_RESIZE_FACTOR 2
62
66#define FIFTYONE_DEGREES_WEIGHTED_ITEM_LIST_DEFAULT_LOAD_FACTOR 4
67
76typedef struct fiftyone_degrees_weighted_item_t {
78 uint32_t rawWeighting;
82
84#define FIFTYONE_DEGREES_WEIGHTED_ITEM_MAX_WEIGHT \
85 ((uint32_t)(((uint32_t)65535)*((uint32_t)65535)))
86
90typedef struct fiftyone_degrees_weighted_item_list_t {
92 uint32_t count;
93 uint32_t capacity;
94 float loadFactor;
96
105 uint32_t initialCapacity,
106 float loadFactor);
107
116
124
134 uint32_t newCapacity,
135 fiftyoneDegreesException *exception);
136
147 const fiftyoneDegreesWeightedItem *item,
148 fiftyoneDegreesException *exception);
149
153
154#endif
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 fiftyoneDegreesWeightedItemListInit(fiftyoneDegreesWeightedItemList *list, uint32_t initialCapacity, float loadFactor)
Initializes a weighted item list with the specified initial 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.
void fiftyoneDegreesWeightedItemListRelease(fiftyoneDegreesWeightedItemList *list)
Releases all collection items in the list and resets the count to zero.
Used to store a handle to the underlying item that could be used to release the item when it's finish...
Definition collection.h:315
Structure used to represent a 51Degrees exception and passed into methods that might generate excepti...
Definition exceptions.h:115
A weighted collection item.
Definition weightedItem.h:76
fiftyoneDegreesCollectionItem item
The collection item containing the value.
Definition weightedItem.h:77
uint32_t rawWeighting
Weight as uint32_t (0-65535^2, representing 0.0-1.0).
Definition weightedItem.h:78
A resizable list of weighted items.
Definition weightedItem.h:90
fiftyoneDegreesWeightedItem * items
Array of weighted items.
Definition weightedItem.h:91
uint32_t count
Number of items currently in use.
Definition weightedItem.h:92
float loadFactor
Load factor threshold for auto-extension.
Definition weightedItem.h:94
uint32_t capacity
Allocated capacity of the items array.
Definition weightedItem.h:93