dictScan() is used to iterate over the elements of a dictionary. * * Iterating works the following way: * * 1) Initially you call the function using a cursor (v) value of 0. * 2) The function performs one step of the iteration, and returns the * new cursor value you must use in the next call. * 3) When the returned cursor is 0, the iteration is complete. * * The function guarantees all
| 885 | * comment is supposed to help. |
| 886 | */ |
| 887 | unsigned long dictScan(dict *d, |
| 888 | unsigned long v, |
| 889 | dictScanFunction *fn, |
| 890 | dictScanBucketFunction* bucketfn, |
| 891 | void *privdata) |
| 892 | { |
| 893 | dictht *t0, *t1; |
| 894 | const dictEntry *de, *next; |
| 895 | unsigned long m0, m1; |
| 896 | |
| 897 | if (dictSize(d) == 0) return 0; |
| 898 | |
| 899 | /* This is needed in case the scan callback tries to do dictFind or alike. */ |
| 900 | dictPauseRehashing(d); |
| 901 | |
| 902 | if (!dictIsRehashing(d)) { |
| 903 | t0 = &(d->ht[0]); |
| 904 | m0 = t0->sizemask; |
| 905 | |
| 906 | /* Emit entries at cursor */ |
| 907 | if (bucketfn) bucketfn(privdata, &t0->table[v & m0]); |
| 908 | de = t0->table[v & m0]; |
| 909 | while (de) { |
| 910 | next = de->next; |
| 911 | fn(privdata, de); |
| 912 | de = next; |
| 913 | } |
| 914 | |
| 915 | /* Set unmasked bits so incrementing the reversed cursor |
| 916 | * operates on the masked bits */ |
| 917 | v |= ~m0; |
| 918 | |
| 919 | /* Increment the reverse cursor */ |
| 920 | v = rev(v); |
| 921 | v++; |
| 922 | v = rev(v); |
| 923 | |
| 924 | } else { |
| 925 | t0 = &d->ht[0]; |
| 926 | t1 = &d->ht[1]; |
| 927 | |
| 928 | /* Make sure t0 is the smaller and t1 is the bigger table */ |
| 929 | if (t0->size > t1->size) { |
| 930 | t0 = &d->ht[1]; |
| 931 | t1 = &d->ht[0]; |
| 932 | } |
| 933 | |
| 934 | m0 = t0->sizemask; |
| 935 | m1 = t1->sizemask; |
| 936 | |
| 937 | /* Emit entries at cursor */ |
| 938 | if (bucketfn) bucketfn(privdata, &t0->table[v & m0]); |
| 939 | de = t0->table[v & m0]; |
| 940 | while (de) { |
| 941 | next = de->next; |
| 942 | fn(privdata, de); |
| 943 | de = next; |
| 944 | } |
no test coverage detected