hashtable

implementing a hash table-like data structure with floating point keys where values within a tolerance are binned together

蓝咒 提交于 2020-12-12 06:49:28
问题 I need an associative data structure with floating point keys in which keys with nearly equal values are binned together. I'm working in C++ but language doesnt really matter. Basically my current strategy is to only handle single precision floating point numbers use an unordered_map with a custom key type define the hash function on the key type as a. given float v divide v by some tolerance, such as 0.0005, at double precision, yielding k . b. cast k to a 64 bit integer yielding ki c.

Redis 2.8.9源码

旧巷老猫 提交于 2020-12-06 18:25:24
Redis使用字典的方式实现了数据库键空间,今天就记录一下字典的实现方式。 Redis 对字典的描述和实现源码在 src/dict.h src/dict.c,关于学习Redis字典如何进行测试或debug,请参考另外一篇文章: Redis 2.8.9源码 - 字典哈希表操作函数头整理,并注释作用和参数说明(附测试方法和代码以及使用方法) 字典结构: typedef struct dict { dictType *type; //根据存储内容的不同,自定义一组回调函数来控制比较申请内存释放空间等操作 void *privdata; //用于回调函数使用 dictht ht[2]; //存放hash表的结构 0 默认使用0,rehash的时候使用1 int rehashidx; //默认为-1,rehash开始的时候该变量设置为0,完成后重新设置为-1 int iterators; //正在进行的安全迭代的数量,释放安全迭代后会减1 } dict; typedef struct dictType { unsigned int (*hashFunction)(const void *key); //针对不同类型进行hash计算的函数,返回hash值 void *(*keyDup)(void *privdata, const void *key); //复制key void *(

Why is the initial capacity in HashMap 16 (power of two) and the initial capacity of Hashtable 11(prime number)?

核能气质少年 提交于 2020-08-19 04:20:10
问题 Please describe the reason if you know. I Googled it, but didn't find well explained answers. Is it for making index of bucket positive when your hashCode is negative? 回答1: For HashMap , the index in the array that stores the entries of the Map is calculated this way (where h is calculated from the hashCode of the key): static int indexFor(int h, int length) { return h & (length-1); } Where length is the length of the array. This only works when length is a power of 2. If length wasn't power

Recompile with -Xlint : unchecked for details

倾然丶 夕夏残阳落幕 提交于 2020-08-11 05:24:32
问题 Hi guys I have this warning on my code. I try to compile using @SuppressWarnings("unchecked") It compile but at the time of the execution the program can't find the main class. How can I solve this problem? Below the code: import java.util.*; @SuppressWarnings("unchecked") class ProgRub { public static void main(String argv[]) { Hashtable rubrica = new Hashtable(20); String chiave, valore; Menu mioMenu = new Menu(); int scelta; scelta = (int) mioMenu.scelta(); while (scelta != 5) { if (scelta