1 /*=============================================================================
2 
3     This file is part of Antic.
4 
5     Antic is free software: you can redistribute it and/or modify it under
6     the terms of the GNU Lesser General Public License (LGPL) as published
7     by the Free Software Foundation; either version 2.1 of the License, or
8     (at your option) any later version. See <http://www.gnu.org/licenses/>.
9 
10 =============================================================================*/
11 /******************************************************************************
12 
13     Copyright (C) 2012 William Hart
14 
15 ******************************************************************************/
16 
17 #include <stdlib.h>
18 #include <gmp.h>
19 #include "flint/fmpz.h"
20 #include "qfb.h"
21 
qfb_hash_find(qfb_hash_t * qhash,qfb_t q,slong depth)22 slong qfb_hash_find(qfb_hash_t * qhash, qfb_t q, slong depth)
23 {
24    slong size = (1L<<depth), i;
25    fmpz_t r;
26 
27    fmpz_init(r);
28 
29    fmpz_fdiv_r_2exp(r, q->a, depth);
30    i = fmpz_get_ui(r);
31 
32    while (!fmpz_is_zero(qhash[i].q->a))
33    {
34       if (fmpz_cmp(qhash[i].q->a, q->a) == 0)
35       {
36          if (fmpz_cmpabs(qhash[i].q->b, q->b) == 0)
37          {
38             fmpz_clear(r);
39             return i;
40          }
41       }
42 
43       i++;
44       if (i == size)
45          i = 0;
46    }
47 
48    fmpz_clear(r);
49    return -1;
50 }
51