1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
/* Pioneers - Implementation of the excellent Settlers of Catan board game.
* Go buy a copy.
*
* Copyright (C) 2013 Roland Clobus <rclobus@rclobus.nl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Implementation of a Set, using a Hash. Based on the glib documentation for HashTables */
#ifndef include_set_h
#define include_set_h
#include <glib.h>
/** An unordered collection of elements.
* Each element occurs only once.
*/
typedef struct _Set Set;
/** Create a new Set.
* @memberof _Set
* @param hash_func a function to create a hash value from the element
* @param equal_func a function to check two elements for equality
* @param destroy a function to free the memory allocated for the element,
* or NULL if you don't want to supply such a function.
* @return a new Set. Free this Set with set_free
*/
Set *set_new(GHashFunc hash_func, GEqualFunc equal_func,
GDestroyNotify destroy);
/** Add a new element to the Set.
* @memberof _Set
* @param set a Set
* @param element the element to add
*/
void set_add(Set * set, gpointer element);
/** Check whether an element is in the Set.
* @memberof _Set
* @param set a Set
* @param element the element to check
* @return TRUE if the element is in the Set
*/
gboolean set_contains(Set * set, gpointer element);
/** Remove an element from the Set.
* @memberof _Set
* @param set a Set
* @param element the element to remove
* @return TRUE if the element was in the Set
*/
gboolean set_remove(Set * set, gpointer element);
/** Returns the number of elements in the Set.
* @memberof _Set
* @param set a Set
* @return The number of elements in the Set.
*/
guint set_size(Set * set);
/** Free the memory associated with the Set.
* @memberof _Set
* @param set a Set
*/
void set_free(Set * set);
typedef void (*SetForEachFunc) (gpointer element, gpointer user_data);
/** Iterate through all elements in the Set.
* @memberof _Set
* @param set a Set
* @param func a function to call for each element
* @param user_data the argument to the function func
*/
void set_foreach(Set * set, SetForEachFunc func, gpointer user_data);
#endif
|