/*
This file is part of GNUnet.
(C) 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2010 Christian Grothoff (and other contributing authors)
GNUnet 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, or (at your
option) any later version.
GNUnet 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 GNUnet; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/**
* @file include/gnunet_container_lib.h
* @brief container classes for GNUnet
*
* @author Christian Grothoff
* @author Nils Durner
*/
#ifndef GNUNET_CONTAINER_LIB_H
#define GNUNET_CONTAINER_LIB_H
/* add error and config prototypes */
#include "gnunet_crypto_lib.h"
#include <extractor.h>
#ifndef EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME
/* hack for LE < 0.6.3 */
#define EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME 180
#endif
#ifdef __cplusplus
extern "C"
{
#if 0 /* keep Emacsens' auto-indent happy */
}
#endif
#endif
/* ******************* bloomfilter ***************** */
/**
* @brief bloomfilter representation (opaque)
*/
struct GNUNET_CONTAINER_BloomFilter;
/**
* Iterator over HashCodes.
*
* @param cls closure
* @param next set to the next hash code
* @return GNUNET_YES if next was updated
* GNUNET_NO if there are no more entries
*/
typedef int (*GNUNET_HashCodeIterator) (void *cls, struct GNUNET_HashCode * next);
/**
* Load a bloom-filter from a file.
*
* @param filename the name of the file (or the prefix)
* @param size the size of the bloom-filter (number of
* bytes of storage space to use); will be rounded up
* to next power of 2
* @param k the number of GNUNET_CRYPTO_hash-functions to apply per
* element (number of bits set per element in the set)
* @return the bloomfilter
*/
struct GNUNET_CONTAINER_BloomFilter *
GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
unsigned int k);
/**
* Create a bloom filter from raw bits.
*
* @param data the raw bits in memory (maybe NULL,
* in which case all bits should be considered
* to be zero).
* @param size the size of the bloom-filter (number of
* bytes of storage space to use); also size of data
* -- unless data is NULL. Must be a power of 2.
* @param k the number of GNUNET_CRYPTO_hash-functions to apply per
* element (number of bits set per element in the set)
* @return the bloomfilter
*/
struct GNUNET_CONTAINER_BloomFilter *
GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size,
unsigned int k);
/**
* Copy the raw data of this bloomfilter into
* the given data array.
*
* @param data where to write the data
* @param size the size of the given data array
* @return GNUNET_SYSERR if the data array of the wrong size
*/
int
GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct
GNUNET_CONTAINER_BloomFilter *bf,
char *data, size_t size);
/**
* Test if an element is in the filter.
* @param e the element
* @param bf the filter
* @return GNUNET_YES if the element is in the filter, GNUNET_NO if not
*/
int
GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter
*bf, const struct GNUNET_HashCode * e);
/**
* Add an element to the fi