]> mj.ucw.cz Git - libucw.git/blob - ucw/sorter/s-radix.h
Merge branch 'master' into table
[libucw.git] / ucw / sorter / s-radix.h
1 /*
2  *      UCW Library -- Universal Sorter: Radix-Split Module
3  *
4  *      (c) 2007 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #include <string.h>
11
12 static void P(radix_split)(struct sort_context *ctx UNUSED, struct sort_bucket *bin, struct sort_bucket **bouts, uint bitpos, uint numbits)
13 {
14   uint nbucks = 1 << numbits;
15   uint mask = nbucks - 1;
16   struct fastbuf *in = sbuck_read(bin);
17   P(key) k;
18
19   struct fastbuf *outs[nbucks];
20   bzero(outs, sizeof(outs));
21
22   while (P(read_key)(in, &k))
23     {
24       P(hash_t) h = P(hash)(&k);
25       uint i = (h >> bitpos) & mask;
26       if (unlikely(!outs[i]))
27         outs[i] = sbuck_write(bouts[i]);
28       P(copy_data)(&k, in, outs[i]);
29     }
30 }