51Degrees Device Detection C/C++  4.1

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 2019 51 Degrees Mobile Experts Limited, 5 Charlotte Close,
4  * Caversham, Reading, Berkshire, United Kingdom RG4 7BY.
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 (EUPL)
13  * 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 #include <windows.h>
117 #endif
118 #include "../common-cxx/data.h"
119 #include "../common-cxx/collection.h"
120 #include "../common-cxx/exceptions.h"
121 
123 #pragma pack(push, 4)
124 typedef struct fiftyoneDegrees_graph_node_hash_t {
125  uint32_t hashCode;
126  int32_t nodeOffset;
129 #pragma pack(pop)
130 
132 typedef struct fiftyoneDegrees_graph_trace_node_t fiftyoneDegreesGraphTraceNode;
140 typedef struct fiftyoneDegrees_graph_trace_node_t {
141  uint32_t index;
144  uint32_t length;
145  uint32_t firstIndex;
146  uint32_t lastIndex;
147  uint32_t hashCode;
149  bool matched;
150  char *rootName;
156 
160 #pragma pack(push, 1)
161 typedef struct fiftyoneDegrees_graph_node_t {
164  byte flags;
165  int16_t firstIndex;
167  int16_t lastIndex;
169  byte length;
170  int32_t hashesCount;
171  int32_t modulo;
173 #pragma pack(pop)
174 
175 #ifndef FIFTYONE_DEGREES_MEMORY_ONLY
176 
188  const fiftyoneDegreesCollectionFile *file,
189  uint32_t offset,
190  fiftyoneDegreesData *data,
191  fiftyoneDegreesException *exception);
192 
193 #endif
194 
206  fiftyoneDegreesCollection *collection,
207  uint32_t offset,
209  fiftyoneDegreesException *exception);
210 
225  uint32_t hash);
226 
238  uint32_t hash);
239 
251  uint32_t hash);
252 
264  uint32_t hash);
265 
277  uint32_t hash);
278 
288  const char *fmt,
289  ...);
290 
296 EXTERNAL void fiftyoneDegreesGraphTraceFree(
298 
305 EXTERNAL void fiftyoneDegreesGraphTraceAppend(
308 
325 EXTERNAL int fiftyoneDegreesGraphTraceGet(
326  char *destination,
327  size_t length,
329  const char *source);
330 
335 #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:149
char * rootName
The name title of the node.
Definition: graph.h:150
fiftyoneDegreesGraphTraceNode * next
Pointer to the next node in the linked list.
Definition: graph.h:153
uint32_t lastIndex
The last index in the hash node.
Definition: graph.h:146
Used to store a handle to the underlying item that could be used to release the item when it's finish...
Definition: collection.h:309
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:124
int16_t lastIndex
Last character index to search for a matching hash code.
Definition: graph.h:167
Type of collection where the collection is streamed from file.
Definition: collection.h:444
uint32_t length
The length of the hashed value being evaluated.
Definition: graph.h:144
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:164
Data structure used for reusing memory which may have been allocated in a previous operation.
Definition: data.h:106
int32_t hashesCount
Number of hash records in the node.
Definition: graph.h:170
void fiftyoneDegreesGraphTraceFree(fiftyoneDegreesGraphTraceNode *route)
Frees a graph trace structure.
byte length
Length of the substring to hash.
Definition: graph.h:169
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:125
uint32_t hashCode
The matched hash code, or zero if no matching hash was found.
Definition: graph.h:147
int32_t nodeOffset
Offset of the node to use if this hash code is a match.
Definition: graph.h:126
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:141
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:165
Structure used to represent a 51Degrees exception and passed into methods that might generate excepti...
Definition: exceptions.h:116
int32_t modulo
Modulo to use when the hashes are a hash table.
Definition: graph.h:171
Trace node structure used to trace the route taken when evaluating a graph.
Definition: graph.h:140
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:161
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:407
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:162
uint32_t firstIndex
The first index in the hash node.
Definition: graph.h:145