source: golgotha/src/i4/memory/bit.hh @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 1.3 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "arch.hh"
10#include "memory/malloc.hh"
11#include <string.h>
12
13
14class i4_bit_array_class
15{
16  w8 static_data[8];
17  w8 *data;
18  public :
19  i4_bit_array_class(w32 length=32, void *bit_data)
20  {
21    if (length<=64) data=static_data;
22    else data=(w8 *)i4_malloc((length+7)/8,"bit array");
23    memcpy(data,bit_data,(length+7)/8);
24  }
25
26  i4_bit_array_class(w32 length=32)
27  {
28    if (length<=64) data=static_data;
29    else data=(w8 *)i4_malloc((length+7)/8,"bit array");
30    memset(data,0,(length+7)/8);
31  }
32
33  i4_bool get(w32 x)
34  {
35    if (data[x/8]&(1<<(x%8)))
36      return i4_T;
37    else return i4_F;
38  }
39
40  void set(w32 x, i4_bool value)
41  {
42    if (value==i4_F)
43      data[x/8]&=~(1<<(x%8));
44    else data[x/8]|=(1<<(x%8));
45  }
46
47  ~i4_bit_array_class()
48  {
49    if (static_data!=data)
50      i4_free(data);
51  }
52} ;
Note: See TracBrowser for help on using the repository browser.