2 * Contains a bitfield used by the GC.
4 * Copyright: Copyright Digital Mars 2005 - 2013.
5 * License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
6 * Authors: Walter Bright, David Friedman, Sean Kelly
9 /* Copyright Digital Mars 2005 - 2013.
10 * Distributed under the Boost Software License, Version 1.0.
11 * (See accompanying file LICENSE or copy at
12 * http://www.boost.org/LICENSE_1_0.txt)
18 import core.stdc.string;
19 import core.stdc.stdlib;
20 import core.exception : onOutOfMemoryError;
24 alias size_t wordtype;
26 enum BITS_PER_WORD = (wordtype.sizeof * 8);
27 enum BITS_SHIFT = (wordtype.sizeof == 8 ? 6 : 5);
28 enum BITS_MASK = (BITS_PER_WORD - 1);
29 enum BITS_1 = cast(wordtype)1;
43 void alloc(size_t nbits) nothrow
46 data = cast(typeof(data[0])*)calloc(nwords, data[0].sizeof);
51 wordtype test(size_t i) const nothrow
58 return core.bitop.bt(data, i);
61 int set(size_t i) nothrow
68 return core.bitop.bts(data, i);
71 int clear(size_t i) nothrow
78 return core.bitop.btr(data, i);
83 memset(data, 0, nwords * wordtype.sizeof);
86 void copy(GCBits *f) nothrow
89 assert(nwords == f.nwords);
93 memcpy(data, f.data, nwords * wordtype.sizeof);
96 @property size_t nwords() const pure nothrow
98 return (nbits + (BITS_PER_WORD - 1)) >> BITS_SHIFT;
107 assert(!b.test(123));
108 assert(!b.clear(123));
111 assert(b.clear(123));
112 assert(!b.test(123));
119 assert(!b.test(785));