| 1 | // Copyright (C) 2000 - 2002 Hewlett-Packard Company |
| 2 | // |
| 3 | // This program is free software; you can redistribute it and/or modify it |
| 4 | // under the term of the GNU Lesser General Public License as published by the |
| 5 | // Free Software Foundation; either version 2 of the License, or (at your |
| 6 | // option) any later version. |
| 7 | // |
| 8 | // This program is distributed in the hope that it will be useful, but WITHOUT |
| 9 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 11 | // for more details. |
| 12 | // |
| 13 | // You should have received a copy of the GNU Lesser General Public License |
| 14 | // along with this program; if not, write to the Free Software Foundation, |
| 15 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 16 | // _________________ |
| 17 | |
| 18 | // @(#) $Revision: 4.7 $ $Source: /judy/src/JudyCommon/JudyMemActive.c $ |
| 19 | // |
| 20 | // Return number of bytes of memory used to support a Judy1/L array. |
| 21 | // Compile with one of -DJUDY1 or -DJUDYL. |
| 22 | |
| 23 | #if (! (defined(JUDY1) || defined(JUDYL))) |
| 24 | #error: One of -DJUDY1 or -DJUDYL must be specified. |
| 25 | #endif |
| 26 | |
| 27 | #ifdef JUDY1 |
| 28 | #include "Judy1.h" |
| 29 | #else |
| 30 | #include "JudyL.h" |
| 31 | #endif |
| 32 | |
| 33 | #include "JudyPrivate1L.h" |
| 34 | |
| 35 | FUNCTION static Word_t j__udyGetMemActive(Pjp_t); |
| 36 | |
| 37 | |
| 38 | // **************************************************************************** |
| 39 | // J U D Y 1 M E M A C T I V E |
| 40 | // J U D Y L M E M A C T I V E |
| 41 | |
| 42 | #ifdef JUDY1 |
| 43 | FUNCTION Word_t Judy1MemActive |
| 44 | #else |
| 45 | FUNCTION Word_t JudyLMemActive |
| 46 | #endif |
| 47 | ( |
| 48 | Pcvoid_t PArray // from which to retrieve. |
| 49 | ) |
| 50 | { |
| 51 | if (PArray == (Pcvoid_t)NULL) return(0); |
| 52 | |
| 53 | if (JU_LEAFW_POP0(PArray) < cJU_LEAFW_MAXPOP1) // must be a LEAFW |
| 54 | { |
| 55 | Pjlw_t Pjlw = P_JLW(PArray); // first word of leaf. |
| 56 | Word_t Words = Pjlw[0] + 1; // population. |
| 57 | #ifdef JUDY1 |
| 58 | return((Words + 1) * sizeof(Word_t)); |
| 59 | #else |
| 60 | return(((Words * 2) + 1) * sizeof(Word_t)); |
| 61 | #endif |
| 62 | } |
| 63 | else |
| 64 | { |
| 65 | Pjpm_t Pjpm = P_JPM(PArray); |
| 66 | return(j__udyGetMemActive(&Pjpm->jpm_JP) + sizeof(jpm_t)); |
| 67 | } |
| 68 | |
| 69 | } // JudyMemActive() |
| 70 | |
| 71 | |
| 72 | // **************************************************************************** |
| 73 | // __ J U D Y G E T M E M A C T I V E |
| 74 | |
| 75 | FUNCTION static Word_t j__udyGetMemActive( |
| 76 | Pjp_t Pjp) // top of subtree. |
| 77 | { |
| 78 | Word_t offset; // in a branch. |
| 79 | Word_t Bytes = 0; // actual bytes used at this level. |
| 80 | Word_t IdxSz; // bytes per index in leaves |
| 81 | |
| 82 | switch (JU_JPTYPE(Pjp)) |
| 83 | { |
| 84 | |
| 85 | case cJU_JPBRANCH_L2: |
| 86 | case cJU_JPBRANCH_L3: |
| 87 | #ifdef JU_64BIT |
| 88 | case cJU_JPBRANCH_L4: |
| 89 | case cJU_JPBRANCH_L5: |
| 90 | case cJU_JPBRANCH_L6: |
| 91 | case cJU_JPBRANCH_L7: |
| 92 | #endif |
| 93 | case cJU_JPBRANCH_L: |
| 94 | { |
| 95 | Pjbl_t Pjbl = P_JBL(Pjp->jp_Addr); |
| 96 | |
| 97 | for (offset = 0; offset < (Pjbl->jbl_NumJPs); ++offset) |
| 98 | Bytes += j__udyGetMemActive((Pjbl->jbl_jp) + offset); |
| 99 | |
| 100 | return(Bytes + sizeof(jbl_t)); |
| 101 | } |
| 102 | |
| 103 | case cJU_JPBRANCH_B2: |
| 104 | case cJU_JPBRANCH_B3: |
| 105 | #ifdef JU_64BIT |
| 106 | case cJU_JPBRANCH_B4: |
| 107 | case cJU_JPBRANCH_B5: |
| 108 | case cJU_JPBRANCH_B6: |
| 109 | case cJU_JPBRANCH_B7: |
| 110 | #endif |
| 111 | case cJU_JPBRANCH_B: |
| 112 | { |
| 113 | Word_t subexp; |
| 114 | Word_t jpcount; |
| 115 | Pjbb_t Pjbb = P_JBB(Pjp->jp_Addr); |
| 116 | |
| 117 | for (subexp = 0; subexp < cJU_NUMSUBEXPB; ++subexp) |
| 118 | { |
| 119 | jpcount = j__udyCountBitsB(JU_JBB_BITMAP(Pjbb, subexp)); |
| 120 | Bytes += jpcount * sizeof(jp_t); |
| 121 | |
| 122 | for (offset = 0; offset < jpcount; ++offset) |
| 123 | { |
| 124 | Bytes += j__udyGetMemActive(P_JP(JU_JBB_PJP(Pjbb, subexp)) |
| 125 | + offset); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | return(Bytes + sizeof(jbb_t)); |
| 130 | } |
| 131 | |
| 132 | case cJU_JPBRANCH_U2: |
| 133 | case cJU_JPBRANCH_U3: |
| 134 | #ifdef JU_64BIT |
| 135 | case cJU_JPBRANCH_U4: |
| 136 | case cJU_JPBRANCH_U5: |
| 137 | case cJU_JPBRANCH_U6: |
| 138 | case cJU_JPBRANCH_U7: |
| 139 | #endif |
| 140 | case cJU_JPBRANCH_U: |
| 141 | { |
| 142 | Pjbu_t Pjbu = P_JBU(Pjp->jp_Addr); |
| 143 | |
| 144 | for (offset = 0; offset < cJU_BRANCHUNUMJPS; ++offset) |
| 145 | { |
| 146 | if (((Pjbu->jbu_jp[offset].jp_Type) >= cJU_JPNULL1) |
| 147 | && ((Pjbu->jbu_jp[offset].jp_Type) <= cJU_JPNULLMAX)) |
| 148 | { |
| 149 | continue; // skip null JP to save time. |
| 150 | } |
| 151 | |
| 152 | Bytes += j__udyGetMemActive(Pjbu->jbu_jp + offset); |
| 153 | } |
| 154 | |
| 155 | return(Bytes + sizeof(jbu_t)); |
| 156 | } |
| 157 | |
| 158 | |
| 159 | // -- Cases below here terminate and do not recurse. -- |
| 160 | |
| 161 | #if (defined(JUDYL) || (! defined(JU_64BIT))) |
| 162 | case cJU_JPLEAF1: IdxSz = 1; goto LeafWords; |
| 163 | #endif |
| 164 | case cJU_JPLEAF2: IdxSz = 2; goto LeafWords; |
| 165 | case cJU_JPLEAF3: IdxSz = 3; goto LeafWords; |
| 166 | #ifdef JU_64BIT |
| 167 | case cJU_JPLEAF4: IdxSz = 4; goto LeafWords; |
| 168 | case cJU_JPLEAF5: IdxSz = 5; goto LeafWords; |
| 169 | case cJU_JPLEAF6: IdxSz = 6; goto LeafWords; |
| 170 | case cJU_JPLEAF7: IdxSz = 7; goto LeafWords; |
| 171 | #endif |
| 172 | LeafWords: |
| 173 | |
| 174 | #ifdef JUDY1 |
| 175 | return(IdxSz * (JU_JPLEAF_POP0(Pjp) + 1)); |
| 176 | #else |
| 177 | return((IdxSz + sizeof(Word_t)) |
| 178 | * (JU_JPLEAF_POP0(Pjp) + 1)); |
| 179 | #endif |
| 180 | case cJU_JPLEAF_B1: |
| 181 | { |
| 182 | #ifdef JUDY1 |
| 183 | return(sizeof(jlb_t)); |
| 184 | #else |
| 185 | Bytes = (JU_JPLEAF_POP0(Pjp) + 1) * sizeof(Word_t); |
| 186 | |
| 187 | return(Bytes + sizeof(jlb_t)); |
| 188 | #endif |
| 189 | } |
| 190 | |
| 191 | JUDY1CODE(case cJ1_JPFULLPOPU1: return(0);) |
| 192 | |
| 193 | #ifdef JUDY1 |
| 194 | #define J__Mpy 0 |
| 195 | #else |
| 196 | #define J__Mpy sizeof(Word_t) |
| 197 | #endif |
| 198 | |
| 199 | case cJU_JPIMMED_1_01: return(0); |
| 200 | case cJU_JPIMMED_2_01: return(0); |
| 201 | case cJU_JPIMMED_3_01: return(0); |
| 202 | #ifdef JU_64BIT |
| 203 | case cJU_JPIMMED_4_01: return(0); |
| 204 | case cJU_JPIMMED_5_01: return(0); |
| 205 | case cJU_JPIMMED_6_01: return(0); |
| 206 | case cJU_JPIMMED_7_01: return(0); |
| 207 | #endif |
| 208 | |
| 209 | case cJU_JPIMMED_1_02: return(J__Mpy * 2); |
| 210 | case cJU_JPIMMED_1_03: return(J__Mpy * 3); |
| 211 | #if (defined(JUDY1) || defined(JU_64BIT)) |
| 212 | case cJU_JPIMMED_1_04: return(J__Mpy * 4); |
| 213 | case cJU_JPIMMED_1_05: return(J__Mpy * 5); |
| 214 | case cJU_JPIMMED_1_06: return(J__Mpy * 6); |
| 215 | case cJU_JPIMMED_1_07: return(J__Mpy * 7); |
| 216 | #endif |
| 217 | #if (defined(JUDY1) && defined(JU_64BIT)) |
| 218 | case cJ1_JPIMMED_1_08: return(0); |
| 219 | case cJ1_JPIMMED_1_09: return(0); |
| 220 | case cJ1_JPIMMED_1_10: return(0); |
| 221 | case cJ1_JPIMMED_1_11: return(0); |
| 222 | case cJ1_JPIMMED_1_12: return(0); |
| 223 | case cJ1_JPIMMED_1_13: return(0); |
| 224 | case cJ1_JPIMMED_1_14: return(0); |
| 225 | case cJ1_JPIMMED_1_15: return(0); |
| 226 | #endif |
| 227 | |
| 228 | #if (defined(JUDY1) || defined(JU_64BIT)) |
| 229 | case cJU_JPIMMED_2_02: return(J__Mpy * 2); |
| 230 | case cJU_JPIMMED_2_03: return(J__Mpy * 3); |
| 231 | #endif |
| 232 | #if (defined(JUDY1) && defined(JU_64BIT)) |
| 233 | case cJ1_JPIMMED_2_04: return(0); |
| 234 | case cJ1_JPIMMED_2_05: return(0); |
| 235 | case cJ1_JPIMMED_2_06: return(0); |
| 236 | case cJ1_JPIMMED_2_07: return(0); |
| 237 | #endif |
| 238 | |
| 239 | #if (defined(JUDY1) || defined(JU_64BIT)) |
| 240 | case cJU_JPIMMED_3_02: return(J__Mpy * 2); |
| 241 | #endif |
| 242 | #if (defined(JUDY1) && defined(JU_64BIT)) |
| 243 | case cJ1_JPIMMED_3_03: return(0); |
| 244 | case cJ1_JPIMMED_3_04: return(0); |
| 245 | case cJ1_JPIMMED_3_05: return(0); |
| 246 | |
| 247 | case cJ1_JPIMMED_4_02: return(0); |
| 248 | case cJ1_JPIMMED_4_03: return(0); |
| 249 | case cJ1_JPIMMED_5_02: return(0); |
| 250 | case cJ1_JPIMMED_5_03: return(0); |
| 251 | case cJ1_JPIMMED_6_02: return(0); |
| 252 | case cJ1_JPIMMED_7_02: return(0); |
| 253 | #endif |
| 254 | |
| 255 | } // switch (JU_JPTYPE(Pjp)) |
| 256 | |
| 257 | return(0); // to make some compilers happy. |
| 258 | |
| 259 | } // j__udyGetMemActive() |