\r\n

51Degrees Device Detection C/C++  4.4

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

graph.h

1 /* *********************************************************************
2  * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3  * Copyright 2022 51 Degrees Mobile Experts Limited, Davidson House,
4  * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
5  *
6  * This Original Work is the subject of the following patents and patent
7  * applications, owned by 51 Degrees Mobile Experts Limited of 5 Charlotte
8  * Close, Caversham, Reading, Berkshire, United Kingdom RG4 7BY:
9  * European Patent No. 3438848; and
10  * United States Patent No. 10,482,175.
11  *
12  * This Original Work is licensed under the European Union Public Licence
13  * (EUPL) v.1.2 and is subject to its terms as set out below.
14  *
15  * If a copy of the EUPL was not distributed with this file, You can obtain
16  * one at https://opensource.org/licenses/EUPL-1.2.
17  *
18  * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
19  * amended by the European Commission) shall be deemed incompatible for
20  * the purposes of the Work and the provisions of the compatibility
21  * clause in Article 5 of the EUPL shall not apply.
22  *
23  * If using the Work as, or as part of, a network application, by
24  * including the attribution notice(s) required under Article 5 of the EUPL
25  * in the end user terms of the application under an appropriate heading,
26  * such notice(s) shall fulfill the requirements of that article.
27  * ********************************************************************* */
28 
29 #ifndef FIFTYONE_DEGREES_GRAPH_INCLUDED
30 #define FIFTYONE_DEGREES_GRAPH_INCLUDED
31 
113 #include <stdint.h>
114 #include <stdbool.h>
115 #ifdef _MSC_VER
116 #pragma warning(push)
117 #pragma warning(disable : 5105)
118 #include <windows.h>
119 #pragma warning(pop)
120 #endif
121 #include "../common-cxx/common.h"
122 #include "../common-cxx/data.h"
123 #include "../common-cxx/collection.h"
124 #include "../common-cxx/exceptions.h"
125 
127 #pragma pack(push, 4)
128 typedef struct fiftyoneDegrees_graph_node_hash_t {
129  uint32_t hashCode;
130  int32_t nodeOffset;
133 #pragma pack(pop)
134 
136 typedef struct fiftyoneDegrees_graph_trace_node_t fiftyoneDegreesGraphTraceNode;
144 typedef struct fiftyoneDegrees_graph_trace_node_t {
145  uint32_t index;
148  uint32_t length;
149  uint32_t firstIndex;
150  uint32_t lastIndex;
151  uint32_t hashCode;
153  bool matched;
154  char *rootName;
160 
164 #pragma pack(push, 1)
165 typedef struct fiftyoneDegrees_graph_node_t {
168  byte flags;
169  int16_t firstIndex;
171  int16_t lastIndex;
173  byte length;
174  int32_t hashesCount;
175  int32_t modulo;
177 #pragma pack(pop)
178 
179 #ifndef FIFTYONE_DEGREES_MEMORY_ONLY
180 
192  const fiftyoneDegreesCollectionFile *file,
193  uint32_t offset,
194  fiftyoneDegreesData *data,
195  fiftyoneDegreesException *exception);
196 
197 #endif
198 
210  fiftyoneDegreesCollection *collection,
211  uint32_t offset,
213  fiftyoneDegreesException *exception);
214 
229  uint32_t hash);
230 
242  uint32_t hash);
243 
255  uint32_t hash);
256 
268  uint32_t hash);
269 
281  uint32_t hash);
282 
292  const char *fmt,
293  ...);
294 
300 EXTERNAL void fiftyoneDegreesGraphTraceFree(
302 
309 EXTERNAL void fiftyoneDegreesGraphTraceAppend(
312 
332 EXTERNAL int fiftyoneDegreesGraphTraceGet(
333  char *destination,
334  size_t length,
336  const char *source);
337 
342 #endif
fiftyoneDegreesGraphNodeHash * fiftyoneDegreesGraphGetMatchingHashFromListNodeSearch(fiftyoneDegreesGraphNode *node, uint32_t hash)
Gets a matching hash record from a node where the hash records are stored as an ordered list by perfo...
bool matched
True if a matching hash was found.
Definition: graph.h:153
char * rootName
The name title of the node.
Definition: graph.h:154
fiftyoneDegreesGraphTraceNode * next
Pointer to the next node in the linked list.
Definition: graph.h:157
uint32_t lastIndex
The last index in the hash node.
Definition: graph.h:150
Used to store a handle to the underlying item that could be used to release the item when it's finish...
Definition: collection.h:310
fiftyoneDegreesGraphNode * fiftyoneDegreesGraphGetNode(fiftyoneDegreesCollection *collection, uint32_t offset, fiftyoneDegreesCollectionItem *item, fiftyoneDegreesException *exception)
Gets the graph node at the requested offset from the graph node collection provided.
fiftyoneDegreesGraphNodeHash * fiftyoneDegreesGraphGetMatchingHashFromListNode(fiftyoneDegreesGraphNode *node, uint32_t hash)
Gets a matching hash record from a node where the node has multiple hash records.
Hash record structure to compare to a substring hash.
Definition: graph.h:128
int16_t lastIndex
Last character index to search for a matching hash code.
Definition: graph.h:171
Type of collection where the collection is streamed from file.
Definition: collection.h:447
uint32_t length
The length of the hashed value being evaluated.
Definition: graph.h:148
void * fiftyoneDegreesGraphNodeReadFromFile(const fiftyoneDegreesCollectionFile *file, uint32_t offset, fiftyoneDegreesData *data, fiftyoneDegreesException *exception)
Read a graph node from the file collection provided and store in the data pointer.
byte flags
Flags available for future implementation.
Definition: graph.h:168
Data structure used for reusing memory which may have been allocated in a previous operation.
Definition: data.h:101
int32_t hashesCount
Number of hash records in the node.
Definition: graph.h:174
void fiftyoneDegreesGraphTraceFree(fiftyoneDegreesGraphTraceNode *route)
Frees a graph trace structure.
byte length
Length of the substring to hash.
Definition: graph.h:173
fiftyoneDegreesGraphNodeHash * fiftyoneDegreesGraphGetMatchingHashFromNode(fiftyoneDegreesGraphNode *node, uint32_t hash)
Gets a matching hash record from a match where the node a single hash record.
uint32_t hashCode
Hash code to compare.
Definition: graph.h:129
uint32_t hashCode
The matched hash code, or zero if no matching hash was found.
Definition: graph.h:151
int32_t nodeOffset
Offset of the node to use if this hash code is a match.
Definition: graph.h:130
fiftyoneDegreesGraphTraceNode * fiftyoneDegreesGraphTraceCreate(const char *fmt,...)
Creates a new graph trace node.
uint32_t index
The index in the evidence where the hash was found, or the last index which was evaluated if no match...
Definition: graph.h:145
int fiftyoneDegreesGraphTraceGet(char *destination, size_t length, fiftyoneDegreesGraphTraceNode *route, const char *source)
Writes a trace route in a readable format to a destination will the memory allocated,...
int16_t firstIndex
First character index to search for a matching hash code.
Definition: graph.h:169
Structure used to represent a 51Degrees exception and passed into methods that might generate excepti...
Definition: exceptions.h:111
int32_t modulo
Modulo to use when the hashes are a hash table.
Definition: graph.h:175
Trace node structure used to trace the route taken when evaluating a graph.
Definition: graph.h:144
void fiftyoneDegreesGraphTraceAppend(fiftyoneDegreesGraphTraceNode *route, fiftyoneDegreesGraphTraceNode *node)
Appends a node to an existing trace route.
Graph node structure used to construct the directed acyclic graph to search.
Definition: graph.h:165
fiftyoneDegreesGraphNodeHash * fiftyoneDegreesGraphGetMatchingHashFromListNodeTable(fiftyoneDegreesGraphNode *node, uint32_t hash)
Gets a matching hash record from a node where the hash records are structured as a hash table.
All the shared methods and fields required by file, memory and cached collections.
Definition: collection.h:410
fiftyoneDegreesGraphNodeHash * fiftyoneDegreesGraphGetMatchingHashFromBinaryNode(fiftyoneDegreesGraphNode *node, uint32_t hash)
Gets a matching hash record from a node where the node a single hash record.
int32_t unmatchedNodeOffset
Offset of the node to use if there is no matching hash record.
Definition: graph.h:166
uint32_t firstIndex
The first index in the hash node.
Definition: graph.h:149