[Home] [Groups] - Message: [Prev in Group] [Next in Group]

nu.kanga.list.mud-dev

6245: Re: [MUD-Dev] caved in: Algorithms for for storing free space.

[Full Header] [Plain Text]
From: Ben Greear <greear@cyberhighway.net>
Newsgroups: nu.kanga.list.mud-dev
Date: Sun, 5 Apr 1998 19:22:14 -0700 (MST)
References: [1]
Organization: Kanga.Nu
On Sun, 5 Apr 1998, Chris Gray wrote:

> [Ben Greear:]
> 
> :A binary search wouldn't be too bad, just wondering if there's
> :a better (constant) method??
> 
> Isn't there one of those bit-twiddle methods that does that? Or can you
> only find the lowest one bit or something? Not sure where to look for
> the stuff, however. Anyone?

I thought of this..might be ok:

int pwr = 0;
int size; //this is what we want to find
int i = 0;

while ((size >> i) > 0) {
	pwr++;
	i++;
}

pwr should be the base of two you'll need.

This is a messy example..and might not even work...just a working
idea.....

Ben

Ben Greear (greear@cyberhighway.net)  http://www.primenet.com/~greear 
Author of ScryMUD:  mud.primenet.com 4444
http://www.primenet.com/~greear/ScryMUD/scry.html