]> mj.ucw.cz Git - libucw.git/blob - lib/sorter/s-radix.h
Created a local TODO list.
[libucw.git] / lib / 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, uns bitpos, uns numbits)
13 {
14   uns nbucks = 1 << numbits;
15   uns 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       uns h = P(hash)(&k);
25       uns 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 }