GDAL

Typedefs | Functions
cpl_hash_set.h File Reference

Hash set implementation. More...

`#include "cpl_port.h"`

Go to the source code of this file.

## Typedefs
typedef struct _CPLHashSet | CPLHashSet
| Opaque type for a hash set.
typedef unsigned long(* | CPLHashSetHashFunc) (const void *elt)
| CPLHashSetHashFunc.
typedef int(* | CPLHashSetEqualFunc) (const void *elt1, const void *elt2)
| CPLHashSetEqualFunc.
typedef void(* | CPLHashSetFreeEltFunc) (void *elt)
| CPLHashSetFreeEltFunc.
typedef int(* | CPLHashSetIterEltFunc) (void *elt, void *user_data)
| CPLHashSetIterEltFunc.

## Functions
CPLHashSet * | CPLHashSetNew (CPLHashSetHashFunc fnHashFunc, CPLHashSetEqualFunc fnEqualFunc, CPLHashSetFreeEltFunc fnFreeEltFunc)
| Creates a new hash set. More...
void | CPLHashSetDestroy (CPLHashSet *set)
| Destroys an allocated hash set. More...
void | CPLHashSetClear (CPLHashSet *set)
| Clear all elements from a hash set. More...
int | CPLHashSetSize (const CPLHashSet *set)
| Returns the number of elements inserted in the hash set. More...
void | CPLHashSetForeach (CPLHashSet *set, CPLHashSetIterEltFunc fnIterFunc, void *user_data)
| Walk through the hash set and runs the provided function on all the elements. More...
int | CPLHashSetInsert (CPLHashSet *set, void *elt)
| Inserts an element into a hash set. More...
void * | CPLHashSetLookup (CPLHashSet *set, const void *elt)
| Returns the element found in the hash set corresponding to the element to look up The element must not be modified. More...
int | CPLHashSetRemove (CPLHashSet *set, const void *elt)
| Removes an element from a hash set. More...
int | CPLHashSetRemoveDeferRehash (CPLHashSet *set, const void *elt)
| Removes an element from a hash set. More...
unsigned long | CPLHashSetHashPointer (const void *elt)
| Hash function for an arbitrary pointer. More...
int | CPLHashSetEqualPointer (const void *elt1, const void *elt2)
| Equality function for arbitrary pointers. More...
unsigned long | CPLHashSetHashStr (const void *pszStr)
| Hash function for a zero-terminated string. More...
int | CPLHashSetEqualStr (const void *pszStr1, const void *pszStr2)
| Equality function for strings. More...

## Detailed Description

Hash set implementation.

An hash set is a data structure that holds elements that are unique according to a comparison function. Operations on the hash set, such as insertion, removal or lookup, are supposed to be fast if an efficient "hash" function is provided.

## Function Documentation

## ◆ CPLHashSetClear()

void CPLHashSetClear | ( | CPLHashSet * | set | ) |

Clear all elements from a hash set.

This function also frees the elements if a free function was provided at the creation of the hash set.

Parameters

  set | the hash set

Since
  GDAL 2.1

## ◆ CPLHashSetDestroy()

void CPLHashSetDestroy | ( | CPLHashSet * | set | ) |

Destroys an allocated hash set.

This function also frees the elements if a free function was provided at the creation of the hash set.

Parameters

  set | the hash set

## ◆ CPLHashSetEqualPointer()

int CPLHashSetEqualPointer | ( | const void * | elt1,
|  | const void * | elt2
| ) |  |

Equality function for arbitrary pointers.

Parameters

  elt1 | the first arbitrary pointer to compare
  elt2 | the second arbitrary pointer to compare

Returns
  TRUE if the pointers are equal

## ◆ CPLHashSetEqualStr()

int CPLHashSetEqualStr | ( | const void * | elt1,
|  | const void * | elt2
| ) |  |

Equality function for strings.

Parameters

  elt1 | the first string to compare. May be NULL.
  elt2 | the second string to compare. May be NULL.

Returns
  TRUE if the strings are equal

## ◆ CPLHashSetForeach()

void CPLHashSetForeach | ( | CPLHashSet * | set,
|  | CPLHashSetIterEltFunc | fnIterFunc,
|  | void * | user_data
| ) |  |

Walk through the hash set and runs the provided function on all the elements.

This function is provided the user_data argument of CPLHashSetForeach. It must return TRUE to go on the walk through the hash set, or FALSE to make it stop.

Note : the structure of the hash set must NOT be modified during the walk.

Parameters

  set | the hash set.
  fnIterFunc | the function called on each element.
  user_data | the user data provided to the function.

## ◆ CPLHashSetHashPointer()

unsigned long CPLHashSetHashPointer | ( | const void * | elt | ) |

Hash function for an arbitrary pointer.

Parameters

  elt | the arbitrary pointer to hash

Returns
  the hash value of the pointer

## ◆ CPLHashSetHashStr()

unsigned long CPLHashSetHashStr | ( | const void * | elt | ) |

Hash function for a zero-terminated string.

Parameters

  elt | the string to hash. May be NULL.

Returns
  the hash value of the string

## ◆ CPLHashSetInsert()

int CPLHashSetInsert | ( | CPLHashSet * | set,
|  | void * | elt
| ) |  |

Inserts an element into a hash set.

If the element was already inserted in the hash set, the previous element is replaced by the new element. If a free function was provided, it is used to free the previously inserted element

Parameters

  set | the hash set
  elt | the new element to insert in the hash set

Returns
  TRUE if the element was not already in the hash set

## ◆ CPLHashSetLookup()

void * CPLHashSetLookup | ( | CPLHashSet * | set,
|  | const void * | elt
| ) |  |

Returns the element found in the hash set corresponding to the element to look up The element must not be modified.

Parameters

  set | the hash set
  elt | the element to look up in the hash set

Returns
  the element found in the hash set or NULL

## ◆ CPLHashSetNew()

CPLHashSet * CPLHashSetNew | ( | CPLHashSetHashFunc | fnHashFunc,
|  | CPLHashSetEqualFunc | fnEqualFunc,
|  | CPLHashSetFreeEltFunc | fnFreeEltFunc
| ) |  |

Creates a new hash set.

The hash function must return a hash value for the elements to insert. If fnHashFunc is NULL, CPLHashSetHashPointer will be used.

The equal function must return if two elements are equal. If fnEqualFunc is NULL, CPLHashSetEqualPointer will be used.

The free function is used to free elements inserted in the hash set, when the hash set is destroyed, when elements are removed or replaced. If fnFreeEltFunc is NULL, elements inserted into the hash set will not be freed.

Parameters

  fnHashFunc | hash function. May be NULL.
  fnEqualFunc | equal function. May be NULL.
  fnFreeEltFunc | element free function. May be NULL.

Returns
  a new hash set

## ◆ CPLHashSetRemove()

int CPLHashSetRemove | ( | CPLHashSet * | set,
|  | const void * | elt
| ) |  |

Removes an element from a hash set.

Parameters

  set | the hash set
  elt | the new element to remove from the hash set

Returns
  TRUE if the element was in the hash set

## ◆ CPLHashSetRemoveDeferRehash()

int CPLHashSetRemoveDeferRehash | ( | CPLHashSet * | set,
|  | const void * | elt
| ) |  |

Removes an element from a hash set.

This will defer potential rehashing of the set to later calls to CPLHashSetInsert() or CPLHashSetRemove().

Parameters

  set | the hash set
  elt | the new element to remove from the hash set

Returns
  TRUE if the element was in the hash set

Since
  GDAL 2.1

## ◆ CPLHashSetSize()

int CPLHashSetSize | ( | const CPLHashSet * | set | ) |

Returns the number of elements inserted in the hash set.

Note: this is not the internal size of the hash set

Parameters

  set | the hash set

Returns
  the number of elements in the hash set