1
// Copyright (C) 2000 - 2002 Hewlett-Packard Company
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.
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
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
18
// @(#) $Revision: 4.7 $ $Source: /judy/src/JudyCommon/JudyMemActive.c $
20
// Return number of bytes of memory used to support a Judy1/L array.
21
// Compile with one of -DJUDY1 or -DJUDYL.
23
#if (! (JUDY1 || JUDYL))
24
Error: One of -DJUDY1 or -DJUDYL must be specified.
33
#include "JudyPrivate1L.h"
35
FUNCTION static Word_t __JudyGetMemActive(Pjp_t);
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
43
FUNCTION Word_t Judy1MemActive(
45
FUNCTION Word_t JudyLMemActive(
47
Pcvoid_t PArray) // from which to retrieve.
49
uint8_t JAPtype; // type of JAP (root pointer).
51
JAPtype = JAPTYPE(PArray);
55
case cJU_JAPNULL: return(0);
57
#if (LOW_POP && JUDYL)
58
case cJL_JAPLEAF_POPU1: return(2 * sizeof(Word_t));
59
case cJL_JAPLEAF_POPU2: return(4 * sizeof(Word_t));
63
Pjlw_t Pjlw = P_JLW(PArray); // first word of leaf.
64
Word_t Words = Pjlw[0] + 1; // population.
66
return((Words + 1) * sizeof(Word_t));
68
return(((Words * 2) + 1) * sizeof(Word_t));
73
Pjpm_t Pjpm = P_JPM(PArray);
74
return(__JudyGetMemActive(&Pjpm->jpm_JP) + sizeof(jpm_t));
81
return(-1); // impossible exit.
86
// ****************************************************************************
87
// __ J U D Y G E T M E M A C T I V E
89
FUNCTION static Word_t __JudyGetMemActive(
90
Pjp_t Pjp) // top of subtree.
92
Word_t offset; // in a branch.
93
Word_t Bytes = 0; // actual bytes used at this level.
94
Word_t IdxSz; // bytes per index in leaves
100
case cJU_JPBRANCH_L3:
102
case cJU_JPBRANCH_L4:
103
case cJU_JPBRANCH_L5:
104
case cJU_JPBRANCH_L6:
105
case cJU_JPBRANCH_L7:
109
Pjbl_t Pjbl = P_JBL(Pjp->jp_Addr);
111
for (offset = 0; offset < (Pjbl->jbl_NumJPs); ++offset)
112
Bytes += __JudyGetMemActive((Pjbl->jbl_jp) + offset);
114
return(Bytes + sizeof(jbl_t));
117
case cJU_JPBRANCH_B2:
118
case cJU_JPBRANCH_B3:
120
case cJU_JPBRANCH_B4:
121
case cJU_JPBRANCH_B5:
122
case cJU_JPBRANCH_B6:
123
case cJU_JPBRANCH_B7:
129
Pjbb_t Pjbb = P_JBB(Pjp->jp_Addr);
131
for (subexp = 0; subexp < cJU_NUMSUBEXPB; ++subexp)
133
jpcount = __JudyCountBitsB(JU_JBB_BITMAP(Pjbb, subexp));
134
Bytes += jpcount * sizeof(jp_t);
136
for (offset = 0; offset < jpcount; ++offset)
138
Bytes += __JudyGetMemActive(P_JP(JU_JBB_PJP(Pjbb, subexp))
143
return(Bytes + sizeof(jbb_t));
146
case cJU_JPBRANCH_U2:
147
case cJU_JPBRANCH_U3:
149
case cJU_JPBRANCH_U4:
150
case cJU_JPBRANCH_U5:
151
case cJU_JPBRANCH_U6:
152
case cJU_JPBRANCH_U7:
156
Pjbu_t Pjbu = P_JBU(Pjp->jp_Addr);
158
for (offset = 0; offset < cJU_BRANCHUNUMJPS; ++offset)
160
if (((Pjbu->jbu_jp[offset].jp_Type) >= cJU_JPNULL1)
161
&& ((Pjbu->jbu_jp[offset].jp_Type) <= cJU_JPNULLMAX))
163
continue; // skip null JP to save time.
166
Bytes += __JudyGetMemActive(Pjbu->jbu_jp + offset);
169
return(Bytes + sizeof(jbu_t));
173
// -- Cases below here terminate and do not recurse. --
175
#if (JUDYL || (! JU_64BIT ))
176
case cJU_JPLEAF1: IdxSz = 1; goto LeafWords;
178
case cJU_JPLEAF2: IdxSz = 2; goto LeafWords;
179
case cJU_JPLEAF3: IdxSz = 3; goto LeafWords;
181
case cJU_JPLEAF4: IdxSz = 4; goto LeafWords;
182
case cJU_JPLEAF5: IdxSz = 5; goto LeafWords;
183
case cJU_JPLEAF6: IdxSz = 6; goto LeafWords;
184
case cJU_JPLEAF7: IdxSz = 7; goto LeafWords;
189
return(IdxSz * (JU_JPLEAF_POP0(Pjp->jp_DcdPop0) + 1));
191
return((IdxSz + sizeof(Word_t))
192
* (JU_JPLEAF_POP0(Pjp->jp_DcdPop0) + 1));
197
return(sizeof(jlb_t));
199
Bytes = (JU_JPLEAF_POP0(Pjp->jp_DcdPop0) + 1) * sizeof(Word_t);
201
return(Bytes + sizeof(jlb_t));
205
JUDY1CODE(case cJ1_JPFULLPOPU1: return(0);)
210
#define __JMpy sizeof(Word_t)
213
case cJU_JPIMMED_1_01: return(0);
214
case cJU_JPIMMED_2_01: return(0);
215
case cJU_JPIMMED_3_01: return(0);
217
case cJU_JPIMMED_4_01: return(0);
218
case cJU_JPIMMED_5_01: return(0);
219
case cJU_JPIMMED_6_01: return(0);
220
case cJU_JPIMMED_7_01: return(0);
223
case cJU_JPIMMED_1_02: return(__JMpy * 2);
224
case cJU_JPIMMED_1_03: return(__JMpy * 3);
225
#if (JUDY1 || JU_64BIT)
226
case cJU_JPIMMED_1_04: return(__JMpy * 4);
227
case cJU_JPIMMED_1_05: return(__JMpy * 5);
228
case cJU_JPIMMED_1_06: return(__JMpy * 6);
229
case cJU_JPIMMED_1_07: return(__JMpy * 7);
231
#if (JUDY1 && JU_64BIT)
232
case cJ1_JPIMMED_1_08: return(0);
233
case cJ1_JPIMMED_1_09: return(0);
234
case cJ1_JPIMMED_1_10: return(0);
235
case cJ1_JPIMMED_1_11: return(0);
236
case cJ1_JPIMMED_1_12: return(0);
237
case cJ1_JPIMMED_1_13: return(0);
238
case cJ1_JPIMMED_1_14: return(0);
239
case cJ1_JPIMMED_1_15: return(0);
242
#if (JUDY1 || JU_64BIT)
243
case cJU_JPIMMED_2_02: return(__JMpy * 2);
244
case cJU_JPIMMED_2_03: return(__JMpy * 3);
246
#if (JUDY1 && JU_64BIT)
247
case cJ1_JPIMMED_2_04: return(0);
248
case cJ1_JPIMMED_2_05: return(0);
249
case cJ1_JPIMMED_2_06: return(0);
250
case cJ1_JPIMMED_2_07: return(0);
253
#if (JUDY1 || JU_64BIT)
254
case cJU_JPIMMED_3_02: return(__JMpy * 2);
256
#if (JUDY1 && JU_64BIT)
257
case cJ1_JPIMMED_3_03: return(0);
258
case cJ1_JPIMMED_3_04: return(0);
259
case cJ1_JPIMMED_3_05: return(0);
261
case cJ1_JPIMMED_4_02: return(0);
262
case cJ1_JPIMMED_4_03: return(0);
263
case cJ1_JPIMMED_5_02: return(0);
264
case cJ1_JPIMMED_5_03: return(0);
265
case cJ1_JPIMMED_6_02: return(0);
266
case cJ1_JPIMMED_7_02: return(0);
269
} // switch (Pjp->jp_Type)
271
return(0); // to make some compilers happy.
273
} // __JudyGetMemActive()