5 * Created by Victor Grishchenko on 10/10/09.
6 * Reimplemented by Alexander G. Pronchenkov on 05/05/10
8 * Copyright 2010 Delft University of Technology. All rights reserved.
16 const bin_t bin_t::NONE(8 * sizeof(bin_t::uint_t), 0);
17 const bin_t bin_t::ALL(8 * sizeof(bin_t::uint_t) - 1, 0);
23 * Gets the layer value of a bin
25 int bin_t::layer(void) const
34 # pragma warning (push)
35 # pragma warning (disable:4146)
39 tail = tail & (-tail);
41 # pragma warning (pop)
44 if (tail > 0x80000000U) {
46 tail >>= 16; // FIXME: hide warning
50 // courtesy of Sean Eron Anderson
51 // http://graphics.stanford.edu/~seander/bithacks.html
52 static const char DeBRUIJN[32] = { 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 };
54 return r + DeBRUIJN[ 0x1f & ((tail * 0x077CB531U) >> 27) ];
57 /* String operations */
61 char* append(char* buf, int x)
89 char* append(char* buf, bin_t::uint_t x)
112 char* append(char* buf, const char* s)
125 char* append(char* buf, char c)
139 * Get the standard-form of this bin, e.g. "(2,1)".
140 * (buffer should have enough of space)
142 const char* bin_t::str(char* buf) const
147 e = append(e, "(ALL)");
148 } else if (is_none()) {
149 e = append(e, "(NONE)");
152 e = append(e, layer());
154 e = append(e, layer_offset());
165 std::ostream & operator << (std::ostream & ostream, const bin_t & bin)
167 char bin_name_buf[64];
168 return ostream << bin.str(bin_name_buf);