hash_log2.c revision 256281
125184Sjkh/*-
2113674Smtm * Copyright (c) 1990, 1993, 1994
3113674Smtm *	The Regents of the University of California.  All rights reserved.
4113674Smtm *
5113674Smtm * This code is derived from software contributed to Berkeley by
6113674Smtm * Margo Seltzer.
7113674Smtm *
8113674Smtm * Redistribution and use in source and binary forms, with or without
9113674Smtm * modification, are permitted provided that the following conditions
10113674Smtm * are met:
11113674Smtm * 1. Redistributions of source code must retain the above copyright
12113674Smtm *    notice, this list of conditions and the following disclaimer.
13113674Smtm * 2. Redistributions in binary form must reproduce the above copyright
14113674Smtm *    notice, this list of conditions and the following disclaimer in the
15113674Smtm *    documentation and/or other materials provided with the distribution.
16113674Smtm * 4. Neither the name of the University nor the names of its contributors
17113674Smtm *    may be used to endorse or promote products derived from this software
18113674Smtm *    without specific prior written permission.
19113674Smtm *
20113674Smtm * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21113674Smtm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22113674Smtm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23113674Smtm * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24113674Smtm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2550472Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2666830Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2725184Sjkh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28113674Smtm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29113674Smtm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30113674Smtm * SUCH DAMAGE.
31113674Smtm */
3225184Sjkh
33178356Ssam#if defined(LIBC_SCCS) && !defined(lint)
34197147Shrsstatic char sccsid[] = "@(#)hash_log2.c	8.2 (Berkeley) 5/31/94";
35197147Shrs#endif /* LIBC_SCCS and not lint */
36178356Ssam#include <sys/cdefs.h>
37178356Ssam__FBSDID("$FreeBSD: stable/10/lib/libc/db/hash/hash_log2.c 190484 2009-03-28 05:45:29Z delphij $");
38178356Ssam
39178356Ssam#include <db.h>
40178356Ssam#include "hash.h"
41178356Ssam#include "page.h"
42178356Ssam#include "extern.h"
43178356Ssam
44178356Ssamu_int32_t
45178356Ssam__log2(u_int32_t num)
46178356Ssam{
47222515Sbz	u_int32_t i, limit;
48222515Sbz
49222515Sbz	limit = 1;
50197139Shrs	for (i = 0; limit < num; limit = limit << 1, i++);
51178356Ssam	return (i);
52178356Ssam}
53178356Ssam