Commit Graph

147 Commits

Author SHA1 Message Date
3e499c1a31 Cleanup: sync edgehash w/ ghash remove logic 2015-11-29 17:51:12 +11:00
09c2bff32f Cleanup: rename hash -> bucket_index, edgehash API
Was confusing since a hash isn't typically used as an index on its own.

Also C99 for loop for bucket resize loop.
2015-11-29 17:51:12 +11:00
472599402f Cleanup: ghash/edgehash style
Call functions on own lines (nicer for debugging)
2015-11-29 17:51:12 +11:00
d7708d135e Partial revert of last commit
Keep index using the outer scope for GHASH iter macros,
while its often nice, in some cases to declare in the for loop,
it means you cant use as a counter after the loop exits, and in some cases signed/unsigned may matter.

API changes should really be split off in their own commits too.
2015-11-26 12:38:31 +11:00
77ac33db7b cleanup: C99 and vertex array comments
GPU_buffer no longer has a fallback to client vertex arrays, so remove
comments about it.

Changed a few internal structs/function interfaces to use bool where
appropriate.

Use for-loop scope and flexible declaration placement. PBVH does the
same thing but needs ~150 fewer lines to do it!

The change to BLI_ghashIterator_init is admittedly hackish but makes
GHASH_ITER_INDEX nicer to use.
2015-11-25 19:49:54 -05:00
09e40a4956 Cleanup: spelling 2015-09-14 02:22:22 +10:00
2b5e150db0 BLI_GHash: add BLI_gset_str_new helpers. 2015-07-02 20:35:05 +02:00
18cf235893 GHash: use const keys when only used for lookups 2015-05-11 12:39:08 +10:00
9e2e85a367 GHash: Add BLI_ghash_ensure_p_ex to copy the key
Needed in cases where the memory from each key is owned by the GHash.
2015-05-11 09:27:05 +10:00
e688ba0304 GHash: use unsigned int for ghash_size 2015-04-13 13:45:48 +10:00
ccf44c400c BMesh: simplify hashing for dyntopo
Was using pointer hashing when the keys are in fact uint's.
Since they're well distributed from the rangetree,
no need to do bit-shifting tricks. just use int as hash.
Gives ~8% speedup in own tests.
2015-04-11 23:36:37 +10:00
dd129125b6 GHash: ensure function, avoids multiple lookups 2015-04-06 20:33:02 +10:00
7157f3dbce GHash: no reason to use GSetEntry in ghash API 2015-04-06 09:08:10 +10:00
b8a6cd0140 Cleanup: comments, style 2015-03-23 22:52:33 +11:00
572489ec89 Fix wrong sizeof() in new ghash hashing helpers code.
Spotted by Coverity.
2015-03-22 21:14:39 +01:00
0025d90b98 Cleanup: use tabs 2015-03-21 16:40:43 +11:00
cfdd27381c GHash - code reorganization, performance enhancements, add a few missing utils to API.
This patch is the root of the GHash rework, all other diff will be based on it:

Reduce average load from 3.0 to 0.75
----------------------------------

This is the big performance booster part, e.g. makes tracing a dyntopo stroke between 25% and 30% faster.

Not much to say about it, aside that it obviously increase memory footprint (about 25% - 30% too).

Add optional shrinking
----------------------------------

I.e. ghashes/gsets can now shrink their buckets array when you remove enough entries. This remains optional and OFF by default.

Add code to use masking instead of modulo
----------------------------------

Buckets indices are obtained from hashes by “reducing” the hash value into the valid bucket range. This can be done either by bit-masking, or using modulo operation.
The former is quicker, but requires real hashes, while the later is slower (average 10% impact on ghash operations) but can also be used as a 'fake' hashing on raw values, like e.g. indices.

In Blender currently not all ghash usages actually hash their keys, so we stick to modulo for now (masking is ifdef’ed out), we may however investigate the benefits of switching to masking with systematic very basic hashing later…

Add various missing API helpers
----------------------------------

I.e. a way to deep-copy a ghash/gset, and a way to (re-)reserve entries (i.e. manually grow or shrink the ghash after its creation).

Various code refactoring
----------------------------------

* Get rid of the 'hack' regarding ghash size when used as gset (it’s simpler and safer to have two structs defined here, and cast pointers as needed).
* Various re-shuffle and factorization in low-level internal code.
* Some work on hashing helpers, introducing some murmur2a-based hashing too.

Thanks a bunch to Campbell for the extensive review work. :)

Reviewers: sergey, campbellbarton

Subscribers: psy-fi, lukastoenne

Projects: #bf_blender

Maniphest Tasks: T43766

Differential Revision: https://developer.blender.org/D1178
2015-03-19 17:37:54 +01:00
fca515838e Cleanup: strcmp/strncmp -> STREQ/STREQLEN (in boolean usage).
Makes usage of those funcs much more clear, we even had mixed '!strcmp(foo, bar)'
and 'strcmp(foo, bar) == 0' in several places...
2015-01-26 16:59:24 +01:00
15bde0dbea Docs: comments (hash table & beauty fill) 2014-12-17 09:58:23 +01:00
a2386b3e20 Fix previous commit rB34abb614f1344a6, which broke addons translations.
Ghash comp callbacks must return false in case a & b are equal!

Also slightly cleaned up gash code using those comp func,
since those return booleans now, let's compare tham against booleans!
2014-09-25 14:33:19 +02:00
6f2f80887b GHash: use bool for comparison (simplify compare) 2014-09-25 06:16:37 +10:00
6be4b39526 GHash: add flag get/set for gset 2014-08-12 13:29:40 +10:00
eedc3834fe Comments 2014-08-11 13:36:35 +10:00
1b6864752f GHash/EdgeHash: avoid NULL check on iterator init 2014-08-07 11:19:55 +10:00
ce0ff266e9 GHash: generic comparison for int[4] 2014-07-30 07:30:18 +10:00
8554fa2fad GHash, EdgeHash: add debugging function to measure the hash quality
Can use to check on improvements to hash functions.
2014-07-14 23:59:47 +10:00
365ff66987 GSet, GHash: Add BLI_gset_add, since its common to add members to a set
also rename BLI_edgeset_reinsert -> BLI_edgeset_add, in this case its the same.
2014-06-14 00:47:12 +10:00
48881ad1e0 Code cleanup: doxy comments 2014-05-14 15:00:47 +10:00
9bff19fbfd GHash, Edgehash: add lookup_default() funcs.
Returns a fallback argument when the key isn't found.
2014-04-22 01:36:59 +10:00
25c9ea8cb3 GHash, EdgeHash: hint on unlikely branch
also avoid searching buckets for empty hashes
2014-04-21 02:50:07 +10:00
aa10cf7f5c GHash: add BLI_ghashutil_uinthash_v4 for hashing 4 ints at once 2014-04-15 14:40:33 +10:00
a7241d09cd GHash: add typed hash functions (were all (void *))
- BLI_ghashutil_strhash_n takes string length, to avoid terminating the string before hashing.
- BLI_ghashutil_inthash/uinthash take ints, to avoid casting to (void *)

This also showed up incorrect use of inthash, which was using a pointer.
2014-04-15 14:22:36 +10:00
5580afb5df GHash/Edgehash: make simple iterator checking functions inline.
also remove NULL check, only a few areas made use of this.
2014-04-08 15:50:38 +10:00
af59ee340f Mempool: remove BLI_MEMPOOL_SYSMALLOC, MEM_* allocs are more efficient now 2014-04-05 12:14:05 +11:00
f9d5bccb06 code cleanup: spelling 2013-10-31 23:52:44 +00:00
1ea9f88ff9 warning cleanup: correct some odd returns and quiet strict flag warnings on some systems. 2013-09-02 17:59:04 +00:00
d59b4752e4 add hash iterator functions to access the pointer to the value. 2013-09-02 02:58:53 +00:00
2924a02a35 move strict compiler checks into a header so its easier to manage in one place (pragmas were copied around).
also enable more strict warnings for BLF (which had some incorrect casts).
2013-09-01 00:46:04 +00:00
b8547074e1 mempool internal change, use unsigned ints where possible (less overhead),
also quiet compiler warning for BLI_LINKSTACK_FREE macro.
2013-08-30 21:32:57 +00:00
8ef934c73f ghash/bli-listbase edits, rename BLI_ghash_pop -> BLI_ghash_popkey (since it takes a key as an arg and isnt popping any element from the hash as you might expect).
add BLI_pophead/tail, since getting the first element from a list and removing it is a common task.
2013-08-26 23:37:08 +00:00
1dba986505 internal changes to ghash/edgehash, reorganize to split out resizing the hash from insertion. 2013-08-26 13:41:13 +00:00
762e7da976 add some safety checks in debug mode to ensure sets/hashes aren't confused. 2013-08-26 09:37:15 +00:00
3b414b9859 minor changes to edgehassh/ghash
- no need to zero vars when freeing ghash
- de duplicate ghash remove code.
- edgehash clear now works more like ghash.
2013-08-25 21:02:31 +00:00
1d5eff36f5 BKI_gset and EdgeSet api, use when hash values aren't used (reuses ghash internally without allocating space for the value). 2013-08-25 20:00:19 +00:00
df01ad250e move doxy docs out of the ghash header into the C file. 2013-08-25 16:28:48 +00:00
e2bd3a4644 clearing the mempool can now keep more then a single element reserved. 2013-08-25 16:16:38 +00:00
28243b2e5f fix leak in BLI_ghash_clear(). was never freeing entries, add BLI_mempool_clear utility function. 2013-08-25 14:58:26 +00:00
3a9eb9b497 doxygen docs for ghash/edgehash 2013-08-25 12:17:46 +00:00
150af65d9f For pointer hashing use the same method as python, it gives better distribution.
some tests with high poly mesh data in hashes.
- empty buckets before 4-5%, after 1-2%
- speedup for hash lookups, in my tests lookups take approx ~60% of the time they did before.
2013-08-24 20:30:08 +00:00
7c65015ab8 use ints for ghash/edgehash flags, since its allocated theres not much point to try save a few bytes here. 2013-08-24 20:16:14 +00:00