1*2639ae9bSBen Gras /* $NetBSD: hash_log2.c,v 1.13 2008/09/11 12:33:55 joerg Exp $ */
2*2639ae9bSBen Gras
3*2639ae9bSBen Gras /*-
4*2639ae9bSBen Gras * Copyright (c) 1990, 1993, 1994
5*2639ae9bSBen Gras * The Regents of the University of California. All rights reserved.
6*2639ae9bSBen Gras *
7*2639ae9bSBen Gras * This code is derived from software contributed to Berkeley by
8*2639ae9bSBen Gras * Margo Seltzer.
9*2639ae9bSBen Gras *
10*2639ae9bSBen Gras * Redistribution and use in source and binary forms, with or without
11*2639ae9bSBen Gras * modification, are permitted provided that the following conditions
12*2639ae9bSBen Gras * are met:
13*2639ae9bSBen Gras * 1. Redistributions of source code must retain the above copyright
14*2639ae9bSBen Gras * notice, this list of conditions and the following disclaimer.
15*2639ae9bSBen Gras * 2. Redistributions in binary form must reproduce the above copyright
16*2639ae9bSBen Gras * notice, this list of conditions and the following disclaimer in the
17*2639ae9bSBen Gras * documentation and/or other materials provided with the distribution.
18*2639ae9bSBen Gras * 3. Neither the name of the University nor the names of its contributors
19*2639ae9bSBen Gras * may be used to endorse or promote products derived from this software
20*2639ae9bSBen Gras * without specific prior written permission.
21*2639ae9bSBen Gras *
22*2639ae9bSBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23*2639ae9bSBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24*2639ae9bSBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25*2639ae9bSBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26*2639ae9bSBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27*2639ae9bSBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28*2639ae9bSBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29*2639ae9bSBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30*2639ae9bSBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31*2639ae9bSBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32*2639ae9bSBen Gras * SUCH DAMAGE.
33*2639ae9bSBen Gras */
34*2639ae9bSBen Gras
35*2639ae9bSBen Gras #if HAVE_NBTOOL_CONFIG_H
36*2639ae9bSBen Gras #include "nbtool_config.h"
37*2639ae9bSBen Gras #endif
38*2639ae9bSBen Gras
39*2639ae9bSBen Gras #include <sys/cdefs.h>
40*2639ae9bSBen Gras __RCSID("$NetBSD: hash_log2.c,v 1.13 2008/09/11 12:33:55 joerg Exp $");
41*2639ae9bSBen Gras
42*2639ae9bSBen Gras #include <sys/types.h>
43*2639ae9bSBen Gras
44*2639ae9bSBen Gras #include <db.h>
45*2639ae9bSBen Gras #include "hash.h"
46*2639ae9bSBen Gras #include "page.h"
47*2639ae9bSBen Gras #include "extern.h"
48*2639ae9bSBen Gras
49*2639ae9bSBen Gras uint32_t
__log2(uint32_t num)50*2639ae9bSBen Gras __log2(uint32_t num)
51*2639ae9bSBen Gras {
52*2639ae9bSBen Gras uint32_t i, limit;
53*2639ae9bSBen Gras
54*2639ae9bSBen Gras if (num == 0)
55*2639ae9bSBen Gras return 0;
56*2639ae9bSBen Gras --num;
57*2639ae9bSBen Gras
58*2639ae9bSBen Gras limit = 0;
59*2639ae9bSBen Gras for (i = 0; limit < num; limit = limit * 2 + 1, i++)
60*2639ae9bSBen Gras continue;
61*2639ae9bSBen Gras return (i);
62*2639ae9bSBen Gras }
63