{"action":"created","comment":{"url":"https://api.github.com/repos/radare/sdb/pulls/comments/68306336","id":68306336,"diff_hunk":"@@ -1,239 +1,184 @@\n-/*\n- * Copyright © 2009 Intel Corporation\n- * Copyright © 1988-2004 Keith Packard and Bart Massey.\n- *\n- * Permission is hereby granted, free of charge, to any person obtaining a\n- * copy of this software and associated documentation files (the \"Software\"),\n- * to deal in the Software without restriction, including without limitation\n- * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n- * and/or sell copies of the Software, and to permit persons to whom the\n- * Software is furnished to do so, subject to the following conditions:\n- *\n- * The above copyright notice and this permission notice (including the next\n- * paragraph) shall be included in all copies or substantial portions of the\n- * Software.\n- *\n- * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\n- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n- * IN THE SOFTWARE.\n- *\n- * Except as contained in this notice, the names of the authors\n- * or their institutions shall not be used in advertising or\n- * otherwise to promote the sale, use or other dealings in this\n- * Software without prior written authorization from the\n- * authors.\n- *\n- * Authors:\n- *    Eric Anholt <eric@anholt.net>\n- *    Keith Packard <keithp@keithp.com>\n- * Integration in r2 core api and hackit up\n- *    pancake <nopcode.org>\n- */\n-\n #include \"ht.h\"\n \n-#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))\n-\n-/*\n- * From Knuth -- a good choice for hash/rehash values is p, p-2 where\n- * p and p-2 are both prime.  These tables are sized to have an extra 10%\n- * free to avoid exponential performance degradation as the hash table fills\n- */\n-\n-static ut32 deleted_data;\n-\n-static const struct {\n-\tut32 max_entries, size, rehash;\n-} hash_sizes[] = {\n-\t{ 2,\t\t5,\t\t3\t  },\n-\t{ 4,\t\t7,\t\t5\t  },\n-\t{ 8,\t\t13,\t\t11\t  },\n-\t{ 16,\t\t19,\t\t17\t  },\n-\t{ 32,\t\t43,\t\t41        },\n-\t{ 64,\t\t73,\t\t71        },\n-\t{ 128,\t\t151,\t\t149       },\n-\t{ 256,\t\t283,\t\t281       },\n-\t{ 512,\t\t571,\t\t569       },\n-\t{ 1024,\t\t1153,\t\t1151      },\n-\t{ 2048,\t\t2269,\t\t2267      },\n-\t{ 4096,\t\t4519,\t\t4517      },\n-\t{ 8192,\t\t9013,\t\t9011      },\n-\t{ 16384,\t18043,\t\t18041     },\n-\t{ 32768,\t36109,\t\t36107     },\n-\t{ 65536,\t72091,\t\t72089     },\n-\t{ 131072,\t144409,\t\t144407    },\n-\t{ 262144,\t288361,\t\t288359    },\n-\t{ 524288,\t576883,\t\t576881    },\n-\t{ 1048576,\t1153459,\t1153457   },\n-\t{ 2097152,\t2307163,\t2307161   },\n-\t{ 4194304,\t4613893,\t4613891   },\n-\t{ 8388608,\t9227641,\t9227639   },\n-\t{ 16777216,\t18455029,\t18455027  },\n-\t{ 33554432,\t36911011,\t36911009  },\n-\t{ 67108864,\t73819861,\t73819859  },\n-\t{ 134217728,\t147639589,\t147639587 },\n-\t{ 268435456,\t295279081,\t295279079 },\n-\t{ 536870912,\t590559793,\t590559791 },\n-\t{ 1073741824,\t1181116273,\t1181116271},\n-\t{ 2147483648ul,\t2362232233ul,\t2362232231ul}\n-};\n-\n-#define entry_is_free(x) (!x || !x->data)\n-#define entry_is_deleted(x) (!x || x->data == &deleted_data)\n-#define entry_is_present(x) (x && x->data && x->data != &deleted_data)\n-\n-/**\n- * Finds a hash table entry with the given key and hash of that key.\n- *\n- * Returns NULL if no entry is found.  Note that the data pointer may be\n- * modified by the user.\n- */\n-SdbHashEntry* ht_search(SdbHash *ht, ut32 hash) {\n-\tut32 double_hash, hash_address;\n-\tif (ht && ht->entries) {\n-\t\thash_address = hash % ht->size;\n-\t\tdo {\n-\t\t\tSdbHashEntry *entry = ht->table + hash_address;\n-\t\t\tif (entry_is_free (entry))\n-\t\t\t\treturn NULL;\n-\t\t\tif (entry_is_present (entry) && entry->hash == hash)\n-\t\t\t\treturn entry;\n-\t\t\tdouble_hash = hash % ht->rehash;\n-\t\t\tif (double_hash == 0)\n-\t\t\t\tdouble_hash = 1;\n-\t\t\thash_address = (hash_address + double_hash) % ht->size;\n-\t\t} while (hash_address != hash % ht->size);\n+SdbHash* internal_ht_new(ut64 size, HashFunction hashfunction,\n+\t\tListComparator comparator, DupKey keydup, DupValue valdup,\n+\t\tHtKvFreeFunc pair_free) {\n+\tSdbHash* ht;\n+\tut32 i;\n+\tht = calloc (1, sizeof(*ht));\n+\tif (ht != NULL) {\n+\t\tht->size = size;\n+\t\tht->count = 0;\n+\t\tht->load_factor = 1;\n+\t\tht->hashfn = hashfunction;\n+\t\tht->cmp = comparator;\n+\t\tht->dupkey = keydup;\n+\t\tht->dupvalue = valdup;\n+\t\tht->table = calloc (ht->size, sizeof (SdbList*));\n+\t\tif (ht->table != NULL) {\n+\t\t\tfor (i = 0; i < ht->size; ++i) {\n+\t\t\t\tht->table[i] = ls_new ();\n+\t\t\t\tif (pair_free) {\n+\t\t\t\t\tht->table[i]->free = (SdbListFree)pair_free;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t} else {\n+\t\t\tfree (ht);","path":"src/ht.c","position":133,"original_position":133,"commit_id":"395c0789747800721b424ee30e961375209b06b6","original_commit_id":"df49a0196bf8ddbd83849180f565fa7dbe9920e9","user":{"login":"crowell","id":616288,"avatar_url":"https://avatars.githubusercontent.com/u/616288?v=3","gravatar_id":"","url":"https://api.github.com/users/crowell","html_url":"https://github.com/crowell","followers_url":"https://api.github.com/users/crowell/followers","following_url":"https://api.github.com/users/crowell/following{/other_user}","gists_url":"https://api.github.com/users/crowell/gists{/gist_id}","starred_url":"https://api.github.com/users/crowell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crowell/subscriptions","organizations_url":"https://api.github.com/users/crowell/orgs","repos_url":"https://api.github.com/users/crowell/repos","events_url":"https://api.github.com/users/crowell/events{/privacy}","received_events_url":"https://api.github.com/users/crowell/received_events","type":"User","site_admin":false},"body":"not any more.","created_at":"2016-06-23T20:14:01Z","updated_at":"2016-06-23T20:14:01Z","html_url":"https://github.com/radare/sdb/pull/102#discussion_r68306336","pull_request_url":"https://api.github.com/repos/radare/sdb/pulls/102","_links":{"self":{"href":"https://api.github.com/repos/radare/sdb/pulls/comments/68306336"},"html":{"href":"https://github.com/radare/sdb/pull/102#discussion_r68306336"},"pull_request":{"href":"https://api.github.com/repos/radare/sdb/pulls/102"}}},"pull_request":{"url":"https://api.github.com/repos/radare/sdb/pulls/102","id":74549040,"html_url":"https://github.com/radare/sdb/pull/102","diff_url":"https://github.com/radare/sdb/pull/102.diff","patch_url":"https://github.com/radare/sdb/pull/102.patch","issue_url":"https://api.github.com/repos/radare/sdb/issues/102","number":102,"state":"open","locked":false,"title":"Rhashtable2","user":{"login":"crowell","id":616288,"avatar_url":"https://avatars.githubusercontent.com/u/616288?v=3","gravatar_id":"","url":"https://api.github.com/users/crowell","html_url":"https://github.com/crowell","followers_url":"https://api.github.com/users/crowell/followers","following_url":"https://api.github.com/users/crowell/following{/other_user}","gists_url":"https://api.github.com/users/crowell/gists{/gist_id}","starred_url":"https://api.github.com/users/crowell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crowell/subscriptions","organizations_url":"https://api.github.com/users/crowell/orgs","repos_url":"https://api.github.com/users/crowell/repos","events_url":"https://api.github.com/users/crowell/events{/privacy}","received_events_url":"https://api.github.com/users/crowell/received_events","type":"User","site_admin":false},"body":"replace the hashtable with one that can handle collisions.\r\n\r\nnot sure how to test this, but it works from my small amount of testing by hand...\r\n\r\n","created_at":"2016-06-21T04:12:53Z","updated_at":"2016-06-23T20:14:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2ec960075b62399546873e41e31ba52cfce2ac1c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/radare/sdb/pulls/102/commits","review_comments_url":"https://api.github.com/repos/radare/sdb/pulls/102/comments","review_comment_url":"https://api.github.com/repos/radare/sdb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/radare/sdb/issues/102/comments","statuses_url":"https://api.github.com/repos/radare/sdb/statuses/395c0789747800721b424ee30e961375209b06b6","head":{"label":"crowell:rhashtable2","ref":"rhashtable2","sha":"395c0789747800721b424ee30e961375209b06b6","user":{"login":"crowell","id":616288,"avatar_url":"https://avatars.githubusercontent.com/u/616288?v=3","gravatar_id":"","url":"https://api.github.com/users/crowell","html_url":"https://github.com/crowell","followers_url":"https://api.github.com/users/crowell/followers","following_url":"https://api.github.com/users/crowell/following{/other_user}","gists_url":"https://api.github.com/users/crowell/gists{/gist_id}","starred_url":"https://api.github.com/users/crowell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crowell/subscriptions","organizations_url":"https://api.github.com/users/crowell/orgs","repos_url":"https://api.github.com/users/crowell/repos","events_url":"https://api.github.com/users/crowell/events{/privacy}","received_events_url":"https://api.github.com/users/crowell/received_events","type":"User","site_admin":false},"repo":{"id":61555905,"name":"sdb","full_name":"crowell/sdb","owner":{"login":"crowell","id":616288,"avatar_url":"https://avatars.githubusercontent.com/u/616288?v=3","gravatar_id":"","url":"https://api.github.com/users/crowell","html_url":"https://github.com/crowell","followers_url":"https://api.github.com/users/crowell/followers","following_url":"https://api.github.com/users/crowell/following{/other_user}","gists_url":"https://api.github.com/users/crowell/gists{/gist_id}","starred_url":"https://api.github.com/users/crowell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crowell/subscriptions","organizations_url":"https://api.github.com/users/crowell/orgs","repos_url":"https://api.github.com/users/crowell/repos","events_url":"https://api.github.com/users/crowell/events{/privacy}","received_events_url":"https://api.github.com/users/crowell/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/crowell/sdb","description":"simple and fast string based key-value database with support for arrays and json","fork":true,"url":"https://api.github.com/repos/crowell/sdb","forks_url":"https://api.github.com/repos/crowell/sdb/forks","keys_url":"https://api.github.com/repos/crowell/sdb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/crowell/sdb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/crowell/sdb/teams","hooks_url":"https://api.github.com/repos/crowell/sdb/hooks","issue_events_url":"https://api.github.com/repos/crowell/sdb/issues/events{/number}","events_url":"https://api.github.com/repos/crowell/sdb/events","assignees_url":"https://api.github.com/repos/crowell/sdb/assignees{/user}","branches_url":"https://api.github.com/repos/crowell/sdb/branches{/branch}","tags_url":"https://api.github.com/repos/crowell/sdb/tags","blobs_url":"https://api.github.com/repos/crowell/sdb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/crowell/sdb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/crowell/sdb/git/refs{/sha}","trees_url":"https://api.github.com/repos/crowell/sdb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/crowell/sdb/statuses/{sha}","languages_url":"https://api.github.com/repos/crowell/sdb/languages","stargazers_url":"https://api.github.com/repos/crowell/sdb/stargazers","contributors_url":"https://api.github.com/repos/crowell/sdb/contributors","subscribers_url":"https://api.github.com/repos/crowell/sdb/subscribers","subscription_url":"https://api.github.com/repos/crowell/sdb/subscription","commits_url":"https://api.github.com/repos/crowell/sdb/commits{/sha}","git_commits_url":"https://api.github.com/repos/crowell/sdb/git/commits{/sha}","comments_url":"https://api.github.com/repos/crowell/sdb/comments{/number}","issue_comment_url":"https://api.github.com/repos/crowell/sdb/issues/comments{/number}","contents_url":"https://api.github.com/repos/crowell/sdb/contents/{+path}","compare_url":"https://api.github.com/repos/crowell/sdb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/crowell/sdb/merges","archive_url":"https://api.github.com/repos/crowell/sdb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/crowell/sdb/downloads","issues_url":"https://api.github.com/repos/crowell/sdb/issues{/number}","pulls_url":"https://api.github.com/repos/crowell/sdb/pulls{/number}","milestones_url":"https://api.github.com/repos/crowell/sdb/milestones{/number}","notifications_url":"https://api.github.com/repos/crowell/sdb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/crowell/sdb/labels{/name}","releases_url":"https://api.github.com/repos/crowell/sdb/releases{/id}","deployments_url":"https://api.github.com/repos/crowell/sdb/deployments","created_at":"2016-06-20T14:54:06Z","updated_at":"2016-06-20T14:54:08Z","pushed_at":"2016-06-23T19:56:28Z","git_url":"git://github.com/crowell/sdb.git","ssh_url":"git@github.com:crowell/sdb.git","clone_url":"https://github.com/crowell/sdb.git","svn_url":"https://github.com/crowell/sdb","homepage":"","size":1237,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"radare:master","ref":"master","sha":"bb7a34768235724727a6ed4279eadfd263fceb44","user":{"login":"radare","id":917142,"avatar_url":"https://avatars.githubusercontent.com/u/917142?v=3","gravatar_id":"","url":"https://api.github.com/users/radare","html_url":"https://github.com/radare","followers_url":"https://api.github.com/users/radare/followers","following_url":"https://api.github.com/users/radare/following{/other_user}","gists_url":"https://api.github.com/users/radare/gists{/gist_id}","starred_url":"https://api.github.com/users/radare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/radare/subscriptions","organizations_url":"https://api.github.com/users/radare/orgs","repos_url":"https://api.github.com/users/radare/repos","events_url":"https://api.github.com/users/radare/events{/privacy}","received_events_url":"https://api.github.com/users/radare/received_events","type":"User","site_admin":false},"repo":{"id":5665061,"name":"sdb","full_name":"radare/sdb","owner":{"login":"radare","id":917142,"avatar_url":"https://avatars.githubusercontent.com/u/917142?v=3","gravatar_id":"","url":"https://api.github.com/users/radare","html_url":"https://github.com/radare","followers_url":"https://api.github.com/users/radare/followers","following_url":"https://api.github.com/users/radare/following{/other_user}","gists_url":"https://api.github.com/users/radare/gists{/gist_id}","starred_url":"https://api.github.com/users/radare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/radare/subscriptions","organizations_url":"https://api.github.com/users/radare/orgs","repos_url":"https://api.github.com/users/radare/repos","events_url":"https://api.github.com/users/radare/events{/privacy}","received_events_url":"https://api.github.com/users/radare/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/radare/sdb","description":"simple and fast string based key-value database with support for arrays and json","fork":false,"url":"https://api.github.com/repos/radare/sdb","forks_url":"https://api.github.com/repos/radare/sdb/forks","keys_url":"https://api.github.com/repos/radare/sdb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/radare/sdb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/radare/sdb/teams","hooks_url":"https://api.github.com/repos/radare/sdb/hooks","issue_events_url":"https://api.github.com/repos/radare/sdb/issues/events{/number}","events_url":"https://api.github.com/repos/radare/sdb/events","assignees_url":"https://api.github.com/repos/radare/sdb/assignees{/user}","branches_url":"https://api.github.com/repos/radare/sdb/branches{/branch}","tags_url":"https://api.github.com/repos/radare/sdb/tags","blobs_url":"https://api.github.com/repos/radare/sdb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/radare/sdb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/radare/sdb/git/refs{/sha}","trees_url":"https://api.github.com/repos/radare/sdb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/radare/sdb/statuses/{sha}","languages_url":"https://api.github.com/repos/radare/sdb/languages","stargazers_url":"https://api.github.com/repos/radare/sdb/stargazers","contributors_url":"https://api.github.com/repos/radare/sdb/contributors","subscribers_url":"https://api.github.com/repos/radare/sdb/subscribers","subscription_url":"https://api.github.com/repos/radare/sdb/subscription","commits_url":"https://api.github.com/repos/radare/sdb/commits{/sha}","git_commits_url":"https://api.github.com/repos/radare/sdb/git/commits{/sha}","comments_url":"https://api.github.com/repos/radare/sdb/comments{/number}","issue_comment_url":"https://api.github.com/repos/radare/sdb/issues/comments{/number}","contents_url":"https://api.github.com/repos/radare/sdb/contents/{+path}","compare_url":"https://api.github.com/repos/radare/sdb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/radare/sdb/merges","archive_url":"https://api.github.com/repos/radare/sdb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/radare/sdb/downloads","issues_url":"https://api.github.com/repos/radare/sdb/issues{/number}","pulls_url":"https://api.github.com/repos/radare/sdb/pulls{/number}","milestones_url":"https://api.github.com/repos/radare/sdb/milestones{/number}","notifications_url":"https://api.github.com/repos/radare/sdb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/radare/sdb/labels{/name}","releases_url":"https://api.github.com/repos/radare/sdb/releases{/id}","deployments_url":"https://api.github.com/repos/radare/sdb/deployments","created_at":"2012-09-03T23:15:15Z","updated_at":"2016-06-03T17:54:38Z","pushed_at":"2016-06-23T19:56:28Z","git_url":"git://github.com/radare/sdb.git","ssh_url":"git@github.com:radare/sdb.git","clone_url":"https://github.com/radare/sdb.git","svn_url":"https://github.com/radare/sdb","homepage":"","size":1275,"stargazers_count":53,"watchers_count":53,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":22,"mirror_url":null,"open_issues_count":25,"forks":22,"open_issues":25,"watchers":53,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/radare/sdb/pulls/102"},"html":{"href":"https://github.com/radare/sdb/pull/102"},"issue":{"href":"https://api.github.com/repos/radare/sdb/issues/102"},"comments":{"href":"https://api.github.com/repos/radare/sdb/issues/102/comments"},"review_comments":{"href":"https://api.github.com/repos/radare/sdb/pulls/102/comments"},"review_comment":{"href":"https://api.github.com/repos/radare/sdb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/radare/sdb/pulls/102/commits"},"statuses":{"href":"https://api.github.com/repos/radare/sdb/statuses/395c0789747800721b424ee30e961375209b06b6"}}}}
{"actor":{"display_login":"crowell"}}