00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2 of the GNU General Public License as 00007 published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU General Public License along 00021 with this program; if not, write the Free Software Foundation, Inc., 59 00022 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00023 00024 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00025 Mountain View, CA 94043, or: 00026 00027 http://www.sgi.com 00028 00029 For further information regarding this notice, see: 00030 00031 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00032 00033 */ 00034 00035 00036 #ifdef USE_PCH 00037 #include "lno_pch.h" 00038 #endif // USE_PCH 00039 #pragma hdrstop 00040 00041 #include "defs.h" 00042 #include "errors.h" 00043 #include "cxx_memory.h" 00044 #include "lno_bv.h" 00045 00046 00047 // Given a positive integer i, returns the equivalence of 2**i 00048 static UINT64 Bit_Pattern64(const UINT bit_pos) { 00049 FmtAssert(bit_pos<64, ("Improper parameter passed to Bit_Pattern64().\n")); 00050 return ((UINT64)1 << (bit_pos)); 00051 } 00052 00053 // 00054 // from John C. Ruttenberg 00055 // Count of bits in all the one byte numbers. Used to count members. 00056 // 00057 static const unsigned char 00058 Pop_Count[256] = { 00059 0, /* 0 */ 1, /* 1 */ 1, /* 2 */ 2, /* 3 */ 1, /* 4 */ 00060 2, /* 5 */ 2, /* 6 */ 3, /* 7 */ 1, /* 8 */ 2, /* 9 */ 00061 2, /* 10 */ 3, /* 11 */ 2, /* 12 */ 3, /* 13 */ 3, /* 14 */ 00062 4, /* 15 */ 1, /* 16 */ 2, /* 17 */ 2, /* 18 */ 3, /* 19 */ 00063 2, /* 20 */ 3, /* 21 */ 3, /* 22 */ 4, /* 23 */ 2, /* 24 */ 00064 3, /* 25 */ 3, /* 26 */ 4, /* 27 */ 3, /* 28 */ 4, /* 29 */ 00065 4, /* 30 */ 5, /* 31 */ 1, /* 32 */ 2, /* 33 */ 2, /* 34 */ 00066 3, /* 35 */ 2, /* 36 */ 3, /* 37 */ 3, /* 38 */ 4, /* 39 */ 00067 2, /* 40 */ 3, /* 41 */ 3, /* 42 */ 4, /* 43 */ 3, /* 44 */ 00068 4, /* 45 */ 4, /* 46 */ 5, /* 47 */ 2, /* 48 */ 3, /* 49 */ 00069 3, /* 50 */ 4, /* 51 */ 3, /* 52 */ 4, /* 53 */ 4, /* 54 */ 00070 5, /* 55 */ 3, /* 56 */ 4, /* 57 */ 4, /* 58 */ 5, /* 59 */ 00071 4, /* 60 */ 5, /* 61 */ 5, /* 62 */ 6, /* 63 */ 1, /* 64 */ 00072 2, /* 65 */ 2, /* 66 */ 3, /* 67 */ 2, /* 68 */ 3, /* 69 */ 00073 3, /* 70 */ 4, /* 71 */ 2, /* 72 */ 3, /* 73 */ 3, /* 74 */ 00074 4, /* 75 */ 3, /* 76 */ 4, /* 77 */ 4, /* 78 */ 5, /* 79 */ 00075 2, /* 80 */ 3, /* 81 */ 3, /* 82 */ 4, /* 83 */ 3, /* 84 */ 00076 4, /* 85 */ 4, /* 86 */ 5, /* 87 */ 3, /* 88 */ 4, /* 89 */ 00077 4, /* 90 */ 5, /* 91 */ 4, /* 92 */ 5, /* 93 */ 5, /* 94 */ 00078 6, /* 95 */ 2, /* 96 */ 3, /* 97 */ 3, /* 98 */ 4, /* 99 */ 00079 3, /* 100 */ 4, /* 101 */ 4, /* 102 */ 5, /* 103 */ 3, /* 104 */ 00080 4, /* 105 */ 4, /* 106 */ 5, /* 107 */ 4, /* 108 */ 5, /* 109 */ 00081 5, /* 110 */ 6, /* 111 */ 3, /* 112 */ 4, /* 113 */ 4, /* 114 */ 00082 5, /* 115 */ 4, /* 116 */ 5, /* 117 */ 5, /* 118 */ 6, /* 119 */ 00083 4, /* 120 */ 5, /* 121 */ 5, /* 122 */ 6, /* 123 */ 5, /* 124 */ 00084 6, /* 125 */ 6, /* 126 */ 7, /* 127 */ 1, /* 128 */ 2, /* 129 */ 00085 2, /* 130 */ 3, /* 131 */ 2, /* 132 */ 3, /* 133 */ 3, /* 134 */ 00086 4, /* 135 */ 2, /* 136 */ 3, /* 137 */ 3, /* 138 */ 4, /* 139 */ 00087 3, /* 140 */ 4, /* 141 */ 4, /* 142 */ 5, /* 143 */ 2, /* 144 */ 00088 3, /* 145 */ 3, /* 146 */ 4, /* 147 */ 3, /* 148 */ 4, /* 149 */ 00089 4, /* 150 */ 5, /* 151 */ 3, /* 152 */ 4, /* 153 */ 4, /* 154 */ 00090 5, /* 155 */ 4, /* 156 */ 5, /* 157 */ 5, /* 158 */ 6, /* 159 */ 00091 2, /* 160 */ 3, /* 161 */ 3, /* 162 */ 4, /* 163 */ 3, /* 164 */ 00092 4, /* 165 */ 4, /* 166 */ 5, /* 167 */ 3, /* 168 */ 4, /* 169 */ 00093 4, /* 170 */ 5, /* 171 */ 4, /* 172 */ 5, /* 173 */ 5, /* 174 */ 00094 6, /* 175 */ 3, /* 176 */ 4, /* 177 */ 4, /* 178 */ 5, /* 179 */ 00095 4, /* 180 */ 5, /* 181 */ 5, /* 182 */ 6, /* 183 */ 4, /* 184 */ 00096 5, /* 185 */ 5, /* 186 */ 6, /* 187 */ 5, /* 188 */ 6, /* 189 */ 00097 6, /* 190 */ 7, /* 191 */ 2, /* 192 */ 3, /* 193 */ 3, /* 194 */ 00098 4, /* 195 */ 3, /* 196 */ 4, /* 197 */ 4, /* 198 */ 5, /* 199 */ 00099 3, /* 200 */ 4, /* 201 */ 4, /* 202 */ 5, /* 203 */ 4, /* 204 */ 00100 5, /* 205 */ 5, /* 206 */ 6, /* 207 */ 3, /* 208 */ 4, /* 209 */ 00101 4, /* 210 */ 5, /* 211 */ 4, /* 212 */ 5, /* 213 */ 5, /* 214 */ 00102 6, /* 215 */ 4, /* 216 */ 5, /* 217 */ 5, /* 218 */ 6, /* 219 */ 00103 5, /* 220 */ 6, /* 221 */ 6, /* 222 */ 7, /* 223 */ 3, /* 224 */ 00104 4, /* 225 */ 4, /* 226 */ 5, /* 227 */ 4, /* 228 */ 5, /* 229 */ 00105 5, /* 230 */ 6, /* 231 */ 4, /* 232 */ 5, /* 233 */ 5, /* 234 */ 00106 6, /* 235 */ 5, /* 236 */ 6, /* 237 */ 6, /* 238 */ 7, /* 239 */ 00107 4, /* 240 */ 5, /* 241 */ 5, /* 242 */ 6, /* 243 */ 5, /* 244 */ 00108 6, /* 245 */ 6, /* 246 */ 7, /* 247 */ 5, /* 248 */ 6, /* 249 */ 00109 6, /* 250 */ 7, /* 251 */ 6, /* 252 */ 7, /* 253 */ 7, /* 254 */ 00110 8 /* 255 */ 00111 }; 00112 00113 // counts how many bits are there in the 64-bit bit vector 'set' 00114 static UINT pop_count64(const UINT64 set) 00115 { 00116 UINT64 temp=set; 00117 char *bytes = (char *)(&temp); 00118 00119 return Pop_Count[bytes[0]] + Pop_Count[bytes[1]] + Pop_Count[bytes[2]] 00120 + Pop_Count[bytes[3]] + Pop_Count[bytes[4]] + Pop_Count[bytes[5]] 00121 + Pop_Count[bytes[6]] + Pop_Count[bytes[7]]; 00122 } 00123 00124 void BIT_VECTOR::Set(UINT bit_position) { 00125 FmtAssert(bit_position<_size, ("Overflow in BIT_VECTOR::set().\n")); 00126 INT i=bit_position/UINT64_size; 00127 INT j=bit_position%UINT64_size; 00128 _bv[i]|=Bit_Pattern64(j); 00129 } 00130 00131 void BIT_VECTOR::Reset(UINT bit_position) { 00132 FmtAssert(bit_position<_size, ("Overflow in BIT_VECTOR::set().\n")); 00133 INT i=bit_position/UINT64_size; 00134 INT j=bit_position%UINT64_size; 00135 _bv[i]&= ~Bit_Pattern64(j); 00136 } 00137 00138 BOOL BIT_VECTOR::Test(UINT bit_position) { 00139 FmtAssert(bit_position<_size, ("Overflow in BIT_VECTOR::test().\n")); 00140 INT i=bit_position/UINT64_size; 00141 INT j=bit_position%UINT64_size; 00142 return (_bv[i] & Bit_Pattern64(j)) != 0; 00143 } 00144 00145 UINT BIT_VECTOR::Pop_Count() { 00146 UINT count=0; 00147 for (INT i=_size-1; i>=0; i-=64) 00148 count+=pop_count64(_bv[i/UINT64_size]); 00149 return count; 00150 } 00151 00152 INT BIT_VECTOR::Least_Non_Zero() { 00153 00154 UINT64 v; 00155 00156 for (INT i=0; i<_size; i+=64) 00157 if ((v=_bv[i/UINT64_size])!=0) { 00158 for (INT j=0; j<64; j++) 00159 if (v & 0x1) 00160 return i*64+j; 00161 else 00162 v = v >> 1; 00163 } 00164 return -1; 00165 } 00166 00167
1.5.6