110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** 210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * @file odb.h 310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * This file contains various definitions and interface for management 410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * of in-memory, through mmaped file, growable hash table, that stores 510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * sample files. 610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * 710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * @remark Copyright 2002 OProfile authors 810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * @remark Read the file COPYING 910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * 1010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * @author Philippe Elie 1110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project */ 1210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 1310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#ifndef ODB_HASH_H 1410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#define ODB_HASH_H 1510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 1610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#include <stddef.h> 1710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#include <stdint.h> 1810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 1910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#include "op_list.h" 2010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 2110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** the type of key. 64-bit because CG needs 32-bit pair {from,to} */ 2210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projecttypedef uint64_t odb_key_t; 2310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** the type of an information in the database */ 2410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projecttypedef unsigned int odb_value_t; 2510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** the type of index (node number), list are implemented through index */ 2610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projecttypedef unsigned int odb_index_t; 2710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** the type store node number */ 2810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projecttypedef odb_index_t odb_node_nr_t; 2910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** store the hash mask, hash table size are always power of two */ 3010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projecttypedef odb_index_t odb_hash_mask_t; 3110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 3210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/* there is (bucket factor * nr node) entry in hash table, this can seem 3310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * excessive but hash coding eip don't give a good distributions and our 3410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * goal is to get a O(1) amortized insert time. bucket factor must be a 3510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * power of two. FIXME: see big comment in odb_hash_add_node, you must 3610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * re-enable zeroing hash table if BUCKET_FACTOR > 2 (roughly exact, you 3710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * want to read the comment in odb_hash_add_node() if you tune this define) 3810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project */ 3910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#define BUCKET_FACTOR 1 4010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 4110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** a db hash node */ 4210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projecttypedef struct { 4310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project odb_key_t key; /**< eip */ 4410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project odb_value_t value; /**< samples count */ 4510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project odb_index_t next; /**< next entry for this bucket */ 4610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} odb_node_t; 4710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 4810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** the minimal information which must be stored in the file to reload 4910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * properly the data base, following this header is the node array then 5010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * the hash table (when growing we avoid to copy node array) 5110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project */ 5210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projecttypedef struct { 5310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project odb_node_nr_t size; /**< in node nr (power of two) */ 5410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project odb_node_nr_t current_size; /**< nr used node + 1, node 0 unused */ 5510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int padding[6]; /**< for padding and future use */ 5610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} odb_descr_t; 5710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 5810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** a "database". this is an in memory only description. 5910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * 6010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * We allow to manage a database inside a mapped file with an "header" of 6110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * unknown size so odb_open get a parameter to specify the size of this header. 6210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * A typical use is: 6310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * 6410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * struct header { int etc; ... }; 6510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * odb_open(&hash, filename, ODB_RW, sizeof(header)); 6610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * so on this library have no dependency on the header type. 6710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * 6810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * the internal memory layout from base_memory is: 6910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * the unknown header (sizeof_header) 7010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * odb_descr_t 7110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * the node array: (descr->size * sizeof(odb_node_t) entries 7210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * the hash table: array of odb_index_t indexing the node array 7310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * (descr->size * BUCKET_FACTOR) entries 7410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project */ 7510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projecttypedef struct odb_data { 7610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project odb_node_t * node_base; /**< base memory area of the page */ 7710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project odb_index_t * hash_base; /**< base memory of hash table */ 7810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project odb_descr_t * descr; /**< the current state of database */ 7910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project odb_hash_mask_t hash_mask; /**< == descr->size - 1 */ 8010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project unsigned int sizeof_header; /**< from base_memory to odb header */ 8110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project unsigned int offset_node; /**< from base_memory to node array */ 8210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project void * base_memory; /**< base memory of the maped memory */ 8310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int fd; /**< mmaped memory file descriptor */ 8410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project char * filename; /**< full path name of sample file */ 8510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int ref_count; /**< reference count */ 8610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project struct list_head list; /**< hash bucket list */ 8710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} odb_data_t; 8810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 8910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projecttypedef struct { 9010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project odb_data_t * data; 9110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} odb_t; 9210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 9310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#ifdef __cplusplus 9410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectextern "C" { 9510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#endif 9610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 9710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/* db_manage.c */ 9810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 9910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** how to open the DB file */ 10010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectenum odb_rw { 10110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project ODB_RDONLY = 0, /**< open for read only */ 10210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project ODB_RDWR = 1 /**< open for read and/or write */ 10310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project}; 10410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 10510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** 10610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * odb_init - initialize a DB file 10710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * @param odb the DB file to init 10810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project */ 10910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectvoid odb_init(odb_t * odb); 11010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 11110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** 11210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * odb_open - open a DB file 11310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * @param odb the data base object to setup 11410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * @param filename the filename where go the maped memory 11510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * @param rw \enum ODB_RW if opening for writing, else \enum ODB_RDONLY 11610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * @param sizeof_header size of the file header if any 11710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * 11810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * The sizeof_header parameter allows the data file to have a header 11910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * at the start of the file which is skipped. 12010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * odb_open() always preallocate a few number of pages. 12110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * returns 0 on success, errno on failure 12210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project */ 12310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectint odb_open(odb_t * odb, char const * filename, 12410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project enum odb_rw rw, size_t sizeof_header); 12510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 12610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** Close the given ODB file */ 12710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectvoid odb_close(odb_t * odb); 12810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 12910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** return the number of times this sample file is open */ 13010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectint odb_open_count(odb_t const * odb); 13110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 13210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** return the start of the mapped data */ 13310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectvoid * odb_get_data(odb_t * odb); 13410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 13510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** issue a msync on the used size of the mmaped file */ 13610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectvoid odb_sync(odb_t const * odb); 13710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 13810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** 13910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * grow the hashtable in such way current_size is the index of the first free 14010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * node. Take care all node pointer can be invalidated by this call. 14110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * 14210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * Node allocation is done in a two step way 1st) ensure a free node exist 14310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * eventually, caller can setup it, 2nd) commit the node allocation with 14410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * odb_commit_reservation(). 14510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * This is done in this way to ensure node setup is visible from another 14610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * process like pp tools in an atomic way. 14710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * 14810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * returns 0 on success, non zero on failure in this case this function do 14910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * nothing and errno is set by the first libc call failure allowing to retry 15010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * after cleanup some program resource. 15110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project */ 15210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectint odb_grow_hashtable(odb_data_t * data); 15310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** 15410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * commit a previously successfull node reservation. This can't fail. 15510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project */ 15610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectstatic __inline void odb_commit_reservation(odb_data_t * data) 15710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 15810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project ++data->descr->current_size; 15910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 16010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 16110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** "immpossible" node number to indicate an error from odb_hash_add_node() */ 16210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#define ODB_NODE_NR_INVALID ((odb_node_nr_t)-1) 16310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 16410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/* db_debug.c */ 16510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** check that the hash is well built */ 16610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectint odb_check_hash(odb_t const * odb); 16710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 16810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/* db_stat.c */ 16910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projecttypedef struct odb_hash_stat_t odb_hash_stat_t; 17010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectodb_hash_stat_t * odb_hash_stat(odb_t const * odb); 17110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectvoid odb_hash_display_stat(odb_hash_stat_t const * stats); 17210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectvoid odb_hash_free_stat(odb_hash_stat_t * stats); 17310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 17410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/* db_insert.c */ 17510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** update info at key by incrementing its associated value by one, 17610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * if the key does not exist a new node is created and the value associated 17710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * is set to one. 17810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * 17910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * returns EXIT_SUCCESS on success, EXIT_FAILURE on failure 18010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project */ 18110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectint odb_update_node(odb_t * odb, odb_key_t key); 18210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 1835a4eb4eb367eccd4b976d1feae96cea96d2c50f2Ben Cheng/** 1845a4eb4eb367eccd4b976d1feae96cea96d2c50f2Ben Cheng * odb_update_node_with_offset 1855a4eb4eb367eccd4b976d1feae96cea96d2c50f2Ben Cheng * @param odb the data base object to setup 1865a4eb4eb367eccd4b976d1feae96cea96d2c50f2Ben Cheng * @param key the hash key 1875a4eb4eb367eccd4b976d1feae96cea96d2c50f2Ben Cheng * @param offset the offset to be added 1885a4eb4eb367eccd4b976d1feae96cea96d2c50f2Ben Cheng * 1895a4eb4eb367eccd4b976d1feae96cea96d2c50f2Ben Cheng * update info at key by adding the specified offset to its associated value, 1905a4eb4eb367eccd4b976d1feae96cea96d2c50f2Ben Cheng * if the key does not exist a new node is created and the value associated 1915a4eb4eb367eccd4b976d1feae96cea96d2c50f2Ben Cheng * is set to offset. 1925a4eb4eb367eccd4b976d1feae96cea96d2c50f2Ben Cheng * 1935a4eb4eb367eccd4b976d1feae96cea96d2c50f2Ben Cheng * returns EXIT_SUCCESS on success, EXIT_FAILURE on failure 1945a4eb4eb367eccd4b976d1feae96cea96d2c50f2Ben Cheng */ 1955a4eb4eb367eccd4b976d1feae96cea96d2c50f2Ben Chengint odb_update_node_with_offset(odb_t * odb, 1965a4eb4eb367eccd4b976d1feae96cea96d2c50f2Ben Cheng odb_key_t key, 1975a4eb4eb367eccd4b976d1feae96cea96d2c50f2Ben Cheng unsigned long int offset); 1985a4eb4eb367eccd4b976d1feae96cea96d2c50f2Ben Cheng 19910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** Add a new node w/o regarding if a node with the same key already exists 20010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * 20110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * returns EXIT_SUCCESS on success, EXIT_FAILURE on failure 20210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project */ 20310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectint odb_add_node(odb_t * odb, odb_key_t key, odb_value_t value); 20410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 20510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/* db_travel.c */ 20610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** 20710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * return a base pointer to the node array and number of node in this array 20810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * caller then will iterate through: 20910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * 21010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * odb_node_nr_t node_nr, pos; 21110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * odb_node_t * node = odb_get_iterator(odb, &node_nr); 21210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * for ( pos = 0 ; pos < node_nr ; ++pos) 21310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * // do something 21410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * 21510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * note than caller does not need to filter nil key as it's a valid key, 21610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * The returned range is all valid (i.e. should never contain zero value). 21710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project */ 21810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectodb_node_t * odb_get_iterator(odb_t const * odb, odb_node_nr_t * nr); 21910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 22010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectstatic __inline unsigned int 22110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectodb_do_hash(odb_data_t const * data, odb_key_t value) 22210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 22310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* FIXME: better hash for eip value, needs to instrument code 22410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * and do a lot of tests ... */ 22510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* trying to combine high order bits his a no-op: inside a binary image 22610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * high order bits don't vary a lot, hash table start with 7 bits mask 22710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * so this hash coding use bits 0-7, 8-15. Hash table is stored in 22810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * files avoiding to rebuilding them at profiling re-start so 22910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * on changing do_hash() change the file format! 23010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project */ 23110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project uint32_t temp = (value >> 32) ^ value; 23210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return ((temp << 0) ^ (temp >> 8)) & data->hash_mask; 23310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 23410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 23510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#ifdef __cplusplus 23610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 23710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#endif 23810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 23910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#endif /* !ODB_H */ 240