]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/tdb2.h
tdb2: add tdb_attribute_seed for setting hash seed.
[ccan] / ccan / tdb2 / tdb2.h
index f856827fcc8f9997598665643b5a0fb44417cec7..adaf67106551f695d5b5384300b88e812190080c 100644 (file)
@@ -40,6 +40,7 @@ extern "C" {
 /* For uint64_t */
 #include <stdint.h>
 #endif
+#include <ccan/compiler/compiler.h>
 
 /* flags to tdb_store() */
 #define TDB_REPLACE 1          /* Unused */
@@ -63,6 +64,9 @@ enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK,
                TDB_ERR_OOM, TDB_ERR_EXISTS, TDB_ERR_NOEXIST,
                TDB_ERR_EINVAL, TDB_ERR_RDONLY, TDB_ERR_NESTING };
 
+/* flags for tdb_summary. Logical or to combine. */
+enum tdb_summary_flags { TDB_SUMMARY_HISTOGRAMS = 1 };
+
 /* debugging uses one of the following levels */
 enum tdb_debug_level {TDB_DEBUG_FATAL = 0, TDB_DEBUG_ERROR, 
                      TDB_DEBUG_WARNING, TDB_DEBUG_TRACE};
@@ -72,18 +76,6 @@ typedef struct tdb_data {
        size_t dsize;
 } TDB_DATA;
 
-#ifndef PRINTF_ATTRIBUTE
-#if (__GNUC__ >= 3)
-/** Use gcc attribute to check printf fns.  a1 is the 1-based index of
- * the parameter containing the format, and a2 the index of the first
- * argument. Note that some gcc 2.x versions don't handle this
- * properly **/
-#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
-#else
-#define PRINTF_ATTRIBUTE(a1, a2)
-#endif
-#endif
-
 struct tdb_context;
 
 /* FIXME: Make typesafe */
@@ -94,7 +86,8 @@ typedef uint64_t (*tdb_hashfn_t)(const void *key, size_t len, uint64_t seed,
 
 enum tdb_attribute_type {
        TDB_ATTRIBUTE_LOG = 0,
-       TDB_ATTRIBUTE_HASH = 1
+       TDB_ATTRIBUTE_HASH = 1,
+       TDB_ATTRIBUTE_SEED = 2
 };
 
 struct tdb_attribute_base {
@@ -114,10 +107,16 @@ struct tdb_attribute_hash {
        void *hash_private;
 };
 
+struct tdb_attribute_seed {
+       struct tdb_attribute_base base; /* .attr = TDB_ATTRIBUTE_SEED */
+       uint64_t seed;
+};
+
 union tdb_attribute {
        struct tdb_attribute_base base;
        struct tdb_attribute_log log;
        struct tdb_attribute_hash hash;
+       struct tdb_attribute_seed seed;
 };
                
 struct tdb_context *tdb_open(const char *name, int tdb_flags,
@@ -143,6 +142,8 @@ int tdb_check(struct tdb_context *tdb,
 enum TDB_ERROR tdb_error(struct tdb_context *tdb);
 const char *tdb_errorstr(struct tdb_context *tdb);
 
+char *tdb_summary(struct tdb_context *tdb, enum tdb_summary_flags flags);
+
 extern struct tdb_data tdb_null;
 
 #ifdef  __cplusplus