Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../usr/include/json-c
File: linkhash.h
/*
[0] Fix | Delete
* $Id: linkhash.h,v 1.6 2006/01/30 23:07:57 mclark Exp $
[1] Fix | Delete
*
[2] Fix | Delete
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
[3] Fix | Delete
* Michael Clark <michael@metaparadigm.com>
[4] Fix | Delete
* Copyright (c) 2009 Hewlett-Packard Development Company, L.P.
[5] Fix | Delete
*
[6] Fix | Delete
* This library is free software; you can redistribute it and/or modify
[7] Fix | Delete
* it under the terms of the MIT license. See COPYING for details.
[8] Fix | Delete
*
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* @file
[13] Fix | Delete
* @brief Internal methods for working with json_type_object objects. Although
[14] Fix | Delete
* this is exposed by the json_object_get_object() function and within the
[15] Fix | Delete
* json_object_iter type, it is not recommended for direct use.
[16] Fix | Delete
*/
[17] Fix | Delete
#ifndef _linkhash_h_
[18] Fix | Delete
#define _linkhash_h_
[19] Fix | Delete
[20] Fix | Delete
#include "json_object.h"
[21] Fix | Delete
[22] Fix | Delete
#ifdef __cplusplus
[23] Fix | Delete
extern "C" {
[24] Fix | Delete
#endif
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* golden prime used in hash functions
[28] Fix | Delete
*/
[29] Fix | Delete
#define LH_PRIME 0x9e370001UL
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* The fraction of filled hash buckets until an insert will cause the table
[33] Fix | Delete
* to be resized.
[34] Fix | Delete
* This can range from just above 0 up to 1.0.
[35] Fix | Delete
*/
[36] Fix | Delete
#define LH_LOAD_FACTOR 0.66
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* sentinel pointer value for empty slots
[40] Fix | Delete
*/
[41] Fix | Delete
#define LH_EMPTY (void*)-1
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* sentinel pointer value for freed slots
[45] Fix | Delete
*/
[46] Fix | Delete
#define LH_FREED (void*)-2
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* default string hash function
[50] Fix | Delete
*/
[51] Fix | Delete
#define JSON_C_STR_HASH_DFLT 0
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* perl-like string hash function
[55] Fix | Delete
*/
[56] Fix | Delete
#define JSON_C_STR_HASH_PERLLIKE 1
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* This function sets the hash function to be used for strings.
[60] Fix | Delete
* Must be one of the JSON_C_STR_HASH_* values.
[61] Fix | Delete
* @returns 0 - ok, -1 if parameter was invalid
[62] Fix | Delete
*/
[63] Fix | Delete
int json_global_set_string_hash(const int h);
[64] Fix | Delete
[65] Fix | Delete
struct lh_entry;
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* callback function prototypes
[69] Fix | Delete
*/
[70] Fix | Delete
typedef void (lh_entry_free_fn) (struct lh_entry *e);
[71] Fix | Delete
/**
[72] Fix | Delete
* callback function prototypes
[73] Fix | Delete
*/
[74] Fix | Delete
typedef unsigned long (lh_hash_fn) (const void *k);
[75] Fix | Delete
/**
[76] Fix | Delete
* callback function prototypes
[77] Fix | Delete
*/
[78] Fix | Delete
typedef int (lh_equal_fn) (const void *k1, const void *k2);
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* An entry in the hash table
[82] Fix | Delete
*/
[83] Fix | Delete
struct lh_entry {
[84] Fix | Delete
/**
[85] Fix | Delete
* The key. Use lh_entry_k() instead of accessing this directly.
[86] Fix | Delete
*/
[87] Fix | Delete
const void *k;
[88] Fix | Delete
/**
[89] Fix | Delete
* A flag for users of linkhash to know whether or not they
[90] Fix | Delete
* need to free k.
[91] Fix | Delete
*/
[92] Fix | Delete
int k_is_constant;
[93] Fix | Delete
/**
[94] Fix | Delete
* The value. Use lh_entry_v() instead of accessing this directly.
[95] Fix | Delete
*/
[96] Fix | Delete
const void *v;
[97] Fix | Delete
/**
[98] Fix | Delete
* The next entry
[99] Fix | Delete
*/
[100] Fix | Delete
struct lh_entry *next;
[101] Fix | Delete
/**
[102] Fix | Delete
* The previous entry.
[103] Fix | Delete
*/
[104] Fix | Delete
struct lh_entry *prev;
[105] Fix | Delete
};
[106] Fix | Delete
[107] Fix | Delete
[108] Fix | Delete
/**
[109] Fix | Delete
* The hash table structure.
[110] Fix | Delete
*/
[111] Fix | Delete
struct lh_table {
[112] Fix | Delete
/**
[113] Fix | Delete
* Size of our hash.
[114] Fix | Delete
*/
[115] Fix | Delete
int size;
[116] Fix | Delete
/**
[117] Fix | Delete
* Numbers of entries.
[118] Fix | Delete
*/
[119] Fix | Delete
int count;
[120] Fix | Delete
[121] Fix | Delete
/**
[122] Fix | Delete
* The first entry.
[123] Fix | Delete
*/
[124] Fix | Delete
struct lh_entry *head;
[125] Fix | Delete
[126] Fix | Delete
/**
[127] Fix | Delete
* The last entry.
[128] Fix | Delete
*/
[129] Fix | Delete
struct lh_entry *tail;
[130] Fix | Delete
[131] Fix | Delete
struct lh_entry *table;
[132] Fix | Delete
[133] Fix | Delete
/**
[134] Fix | Delete
* A pointer onto the function responsible for freeing an entry.
[135] Fix | Delete
*/
[136] Fix | Delete
lh_entry_free_fn *free_fn;
[137] Fix | Delete
lh_hash_fn *hash_fn;
[138] Fix | Delete
lh_equal_fn *equal_fn;
[139] Fix | Delete
};
[140] Fix | Delete
typedef struct lh_table lh_table;
[141] Fix | Delete
[142] Fix | Delete
[143] Fix | Delete
/**
[144] Fix | Delete
* Convenience list iterator.
[145] Fix | Delete
*/
[146] Fix | Delete
#define lh_foreach(table, entry) \
[147] Fix | Delete
for(entry = table->head; entry; entry = entry->next)
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* lh_foreach_safe allows calling of deletion routine while iterating.
[151] Fix | Delete
*
[152] Fix | Delete
* @param table a struct lh_table * to iterate over
[153] Fix | Delete
* @param entry a struct lh_entry * variable to hold each element
[154] Fix | Delete
* @param tmp a struct lh_entry * variable to hold a temporary pointer to the next element
[155] Fix | Delete
*/
[156] Fix | Delete
#define lh_foreach_safe(table, entry, tmp) \
[157] Fix | Delete
for(entry = table->head; entry && ((tmp = entry->next) || 1); entry = tmp)
[158] Fix | Delete
[159] Fix | Delete
[160] Fix | Delete
[161] Fix | Delete
/**
[162] Fix | Delete
* Create a new linkhash table.
[163] Fix | Delete
*
[164] Fix | Delete
* @param size initial table size. The table is automatically resized
[165] Fix | Delete
* although this incurs a performance penalty.
[166] Fix | Delete
* @param free_fn callback function used to free memory for entries
[167] Fix | Delete
* when lh_table_free or lh_table_delete is called.
[168] Fix | Delete
* If NULL is provided, then memory for keys and values
[169] Fix | Delete
* must be freed by the caller.
[170] Fix | Delete
* @param hash_fn function used to hash keys. 2 standard ones are defined:
[171] Fix | Delete
* lh_ptr_hash and lh_char_hash for hashing pointer values
[172] Fix | Delete
* and C strings respectively.
[173] Fix | Delete
* @param equal_fn comparison function to compare keys. 2 standard ones defined:
[174] Fix | Delete
* lh_ptr_hash and lh_char_hash for comparing pointer values
[175] Fix | Delete
* and C strings respectively.
[176] Fix | Delete
* @return On success, a pointer to the new linkhash table is returned.
[177] Fix | Delete
* On error, a null pointer is returned.
[178] Fix | Delete
*/
[179] Fix | Delete
extern struct lh_table* lh_table_new(int size,
[180] Fix | Delete
lh_entry_free_fn *free_fn,
[181] Fix | Delete
lh_hash_fn *hash_fn,
[182] Fix | Delete
lh_equal_fn *equal_fn);
[183] Fix | Delete
[184] Fix | Delete
/**
[185] Fix | Delete
* Convenience function to create a new linkhash table with char keys.
[186] Fix | Delete
*
[187] Fix | Delete
* @param size initial table size.
[188] Fix | Delete
* @param free_fn callback function used to free memory for entries.
[189] Fix | Delete
* @return On success, a pointer to the new linkhash table is returned.
[190] Fix | Delete
* On error, a null pointer is returned.
[191] Fix | Delete
*/
[192] Fix | Delete
extern struct lh_table* lh_kchar_table_new(int size,
[193] Fix | Delete
lh_entry_free_fn *free_fn);
[194] Fix | Delete
[195] Fix | Delete
[196] Fix | Delete
/**
[197] Fix | Delete
* Convenience function to create a new linkhash table with ptr keys.
[198] Fix | Delete
*
[199] Fix | Delete
* @param size initial table size.
[200] Fix | Delete
* @param free_fn callback function used to free memory for entries.
[201] Fix | Delete
* @return On success, a pointer to the new linkhash table is returned.
[202] Fix | Delete
* On error, a null pointer is returned.
[203] Fix | Delete
*/
[204] Fix | Delete
extern struct lh_table* lh_kptr_table_new(int size,
[205] Fix | Delete
lh_entry_free_fn *free_fn);
[206] Fix | Delete
[207] Fix | Delete
[208] Fix | Delete
/**
[209] Fix | Delete
* Free a linkhash table.
[210] Fix | Delete
*
[211] Fix | Delete
* If a lh_entry_free_fn callback free function was provided then it is
[212] Fix | Delete
* called for all entries in the table.
[213] Fix | Delete
*
[214] Fix | Delete
* @param t table to free.
[215] Fix | Delete
*/
[216] Fix | Delete
extern void lh_table_free(struct lh_table *t);
[217] Fix | Delete
[218] Fix | Delete
[219] Fix | Delete
/**
[220] Fix | Delete
* Insert a record into the table.
[221] Fix | Delete
*
[222] Fix | Delete
* @param t the table to insert into.
[223] Fix | Delete
* @param k a pointer to the key to insert.
[224] Fix | Delete
* @param v a pointer to the value to insert.
[225] Fix | Delete
*
[226] Fix | Delete
* @return On success, <code>0</code> is returned.
[227] Fix | Delete
* On error, a negative value is returned.
[228] Fix | Delete
*/
[229] Fix | Delete
extern int lh_table_insert(struct lh_table *t, const void *k, const void *v);
[230] Fix | Delete
[231] Fix | Delete
[232] Fix | Delete
/**
[233] Fix | Delete
* Insert a record into the table using a precalculated key hash.
[234] Fix | Delete
*
[235] Fix | Delete
* The hash h, which should be calculated with lh_get_hash() on k, is provided by
[236] Fix | Delete
* the caller, to allow for optimization when multiple operations with the same
[237] Fix | Delete
* key are known to be needed.
[238] Fix | Delete
*
[239] Fix | Delete
* @param t the table to insert into.
[240] Fix | Delete
* @param k a pointer to the key to insert.
[241] Fix | Delete
* @param v a pointer to the value to insert.
[242] Fix | Delete
* @param h hash value of the key to insert
[243] Fix | Delete
* @param opts if set to JSON_C_OBJECT_KEY_IS_CONSTANT, sets lh_entry.k_is_constant
[244] Fix | Delete
* so t's free function knows to avoid freeing the key.
[245] Fix | Delete
*/
[246] Fix | Delete
extern int lh_table_insert_w_hash(struct lh_table *t, const void *k, const void *v, const unsigned long h, const unsigned opts);
[247] Fix | Delete
[248] Fix | Delete
[249] Fix | Delete
/**
[250] Fix | Delete
* Lookup a record in the table.
[251] Fix | Delete
*
[252] Fix | Delete
* @param t the table to lookup
[253] Fix | Delete
* @param k a pointer to the key to lookup
[254] Fix | Delete
* @return a pointer to the record structure of the value or NULL if it does not exist.
[255] Fix | Delete
*/
[256] Fix | Delete
extern struct lh_entry* lh_table_lookup_entry(struct lh_table *t, const void *k);
[257] Fix | Delete
[258] Fix | Delete
/**
[259] Fix | Delete
* Lookup a record in the table using a precalculated key hash.
[260] Fix | Delete
*
[261] Fix | Delete
* The hash h, which should be calculated with lh_get_hash() on k, is provided by
[262] Fix | Delete
* the caller, to allow for optimization when multiple operations with the same
[263] Fix | Delete
* key are known to be needed.
[264] Fix | Delete
*
[265] Fix | Delete
* @param t the table to lookup
[266] Fix | Delete
* @param k a pointer to the key to lookup
[267] Fix | Delete
* @param h hash value of the key to lookup
[268] Fix | Delete
* @return a pointer to the record structure of the value or NULL if it does not exist.
[269] Fix | Delete
*/
[270] Fix | Delete
extern struct lh_entry* lh_table_lookup_entry_w_hash(struct lh_table *t, const void *k, const unsigned long h);
[271] Fix | Delete
[272] Fix | Delete
/**
[273] Fix | Delete
* Lookup a record into the table.
[274] Fix | Delete
*
[275] Fix | Delete
* @param t the table to lookup
[276] Fix | Delete
* @param k a pointer to the key to lookup
[277] Fix | Delete
* @return a pointer to the found value or NULL if it does not exist.
[278] Fix | Delete
* @deprecated Use lh_table_lookup_ex() instead.
[279] Fix | Delete
*/
[280] Fix | Delete
THIS_FUNCTION_IS_DEPRECATED(extern const void* lh_table_lookup(struct lh_table *t, const void *k));
[281] Fix | Delete
[282] Fix | Delete
/**
[283] Fix | Delete
* Lookup a record in the table.
[284] Fix | Delete
*
[285] Fix | Delete
* @param t the table to lookup
[286] Fix | Delete
* @param k a pointer to the key to lookup
[287] Fix | Delete
* @param v a pointer to a where to store the found value (set to NULL if it doesn't exist).
[288] Fix | Delete
* @return whether or not the key was found
[289] Fix | Delete
*/
[290] Fix | Delete
extern json_bool lh_table_lookup_ex(struct lh_table *t, const void *k, void **v);
[291] Fix | Delete
[292] Fix | Delete
/**
[293] Fix | Delete
* Delete a record from the table.
[294] Fix | Delete
*
[295] Fix | Delete
* If a callback free function is provided then it is called for the
[296] Fix | Delete
* for the item being deleted.
[297] Fix | Delete
* @param t the table to delete from.
[298] Fix | Delete
* @param e a pointer to the entry to delete.
[299] Fix | Delete
* @return 0 if the item was deleted.
[300] Fix | Delete
* @return -1 if it was not found.
[301] Fix | Delete
*/
[302] Fix | Delete
extern int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e);
[303] Fix | Delete
[304] Fix | Delete
[305] Fix | Delete
/**
[306] Fix | Delete
* Delete a record from the table.
[307] Fix | Delete
*
[308] Fix | Delete
* If a callback free function is provided then it is called for the
[309] Fix | Delete
* for the item being deleted.
[310] Fix | Delete
* @param t the table to delete from.
[311] Fix | Delete
* @param k a pointer to the key to delete.
[312] Fix | Delete
* @return 0 if the item was deleted.
[313] Fix | Delete
* @return -1 if it was not found.
[314] Fix | Delete
*/
[315] Fix | Delete
extern int lh_table_delete(struct lh_table *t, const void *k);
[316] Fix | Delete
[317] Fix | Delete
extern int lh_table_length(struct lh_table *t);
[318] Fix | Delete
[319] Fix | Delete
/**
[320] Fix | Delete
* Prints a message to <code>stdout</code>,
[321] Fix | Delete
* then exits the program with an exit code of <code>1</code>.
[322] Fix | Delete
*
[323] Fix | Delete
* @param msg Message format string, like for <code>printf</code>.
[324] Fix | Delete
* @param ... Format args.
[325] Fix | Delete
*
[326] Fix | Delete
* @deprecated Since it is not a good idea to exit the entire program
[327] Fix | Delete
* because of an internal library failure, json-c will no longer
[328] Fix | Delete
* use this function internally.
[329] Fix | Delete
* However, because its interface is public, it will remain part of
[330] Fix | Delete
* the API on the off chance of legacy software using it externally.
[331] Fix | Delete
*/
[332] Fix | Delete
THIS_FUNCTION_IS_DEPRECATED(void lh_abort(const char *msg, ...));
[333] Fix | Delete
[334] Fix | Delete
/**
[335] Fix | Delete
* Resizes the specified table.
[336] Fix | Delete
*
[337] Fix | Delete
* @param t Pointer to table to resize.
[338] Fix | Delete
* @param new_size New table size. Must be positive.
[339] Fix | Delete
*
[340] Fix | Delete
* @return On success, <code>0</code> is returned.
[341] Fix | Delete
* On error, a negative value is returned.
[342] Fix | Delete
*/
[343] Fix | Delete
int lh_table_resize(struct lh_table *t, int new_size);
[344] Fix | Delete
[345] Fix | Delete
[346] Fix | Delete
/**
[347] Fix | Delete
* @deprecated Don't use this outside of linkhash.h:
[348] Fix | Delete
*/
[349] Fix | Delete
#if !defined(_MSC_VER) || (_MSC_VER > 1800)
[350] Fix | Delete
/* VS2010 can't handle inline funcs, so skip it there */
[351] Fix | Delete
#define _LH_INLINE inline
[352] Fix | Delete
#else
[353] Fix | Delete
#define _LH_INLINE
[354] Fix | Delete
#endif
[355] Fix | Delete
[356] Fix | Delete
/**
[357] Fix | Delete
* Calculate the hash of a key for a given table.
[358] Fix | Delete
*
[359] Fix | Delete
* This is an exension to support functions that need to calculate
[360] Fix | Delete
* the hash several times and allows them to do it just once and then pass
[361] Fix | Delete
* in the hash to all utility functions. Depending on use case, this can be a
[362] Fix | Delete
* considerable performance improvement.
[363] Fix | Delete
* @param t the table (used to obtain hash function)
[364] Fix | Delete
* @param k a pointer to the key to lookup
[365] Fix | Delete
* @return the key's hash
[366] Fix | Delete
*/
[367] Fix | Delete
static _LH_INLINE unsigned long lh_get_hash(const struct lh_table *t, const void *k)
[368] Fix | Delete
{
[369] Fix | Delete
return t->hash_fn(k);
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
#undef _LH_INLINE
[373] Fix | Delete
[374] Fix | Delete
/**
[375] Fix | Delete
* @deprecated Don't use this outside of linkhash.h:
[376] Fix | Delete
*/
[377] Fix | Delete
#ifdef __UNCONST
[378] Fix | Delete
#define _LH_UNCONST(a) __UNCONST(a)
[379] Fix | Delete
#else
[380] Fix | Delete
#define _LH_UNCONST(a) ((void *)(uintptr_t)(const void *)(a))
[381] Fix | Delete
#endif
[382] Fix | Delete
[383] Fix | Delete
/**
[384] Fix | Delete
* Return a non-const version of lh_entry.k.
[385] Fix | Delete
*
[386] Fix | Delete
* lh_entry.k is const to indicate and help ensure that linkhash itself doesn't modify
[387] Fix | Delete
* it, but callers are allowed to do what they want with it.
[388] Fix | Delete
* See also lh_entry.k_is_constant
[389] Fix | Delete
*/
[390] Fix | Delete
#define lh_entry_k(entry) _LH_UNCONST((entry)->k)
[391] Fix | Delete
[392] Fix | Delete
/**
[393] Fix | Delete
* Return a non-const version of lh_entry.v.
[394] Fix | Delete
*
[395] Fix | Delete
* v is const to indicate and help ensure that linkhash itself doesn't modify
[396] Fix | Delete
* it, but callers are allowed to do what they want with it.
[397] Fix | Delete
*/
[398] Fix | Delete
#define lh_entry_v(entry) _LH_UNCONST((entry)->v)
[399] Fix | Delete
[400] Fix | Delete
#ifdef __cplusplus
[401] Fix | Delete
}
[402] Fix | Delete
#endif
[403] Fix | Delete
[404] Fix | Delete
#endif
[405] Fix | Delete
[406] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function