Skip to content

Commit 8a1fe07

Browse files
committed
create dicstats function, use for nkeys
1 parent ecb2aaa commit 8a1fe07

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

jsrc/je.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ extern F2(jtdex);
480480
extern F2(jtdgrade2);
481481
extern DF1(jtdicdelc);
482482
extern DF2(jtdicempties);
483+
extern DF2(jtdicstats);
483484
extern DF1(jtdicgetc);
484485
extern DF1(jtdichasc);
485486
extern DF1(jtdicgetkvc);

jsrc/x.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ void jtforeigninit(J jt){UI i;
199199
MN(16,0) XPRIM(VERB, jthashy, jttao, VASGSAFE,VF2NONE,RMAX, RMAX,RMAX);
200200
MN(16,-1) XPRIM(ADV, jtcreatedic, 0, VASGSAFE,VF2NONE,RMAX, RMAX,RMAX);
201201
MN(16,-5) XPRIM(VERB, 0, jtdicempties, VASGSAFE,VF2NONE,RMAX, RMAX,RMAX);
202+
MN(16,-8) XPRIM(VERB, 0, jtdicstats, VASGSAFE,VF2NONE,RMAX, RMAX,RMAX);
202203
MN(2,0) XPRIM(VERB, jthost, 0, VASGSAFE,VF2NONE,1, RMAX,RMAX);
203204
MN(2,1) XPRIM(VERB, jthostne, 0, VASGSAFE,VF2NONE,1, RMAX,RMAX);
204205
#if 0 // doesn't work

jsrc/xdic.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ notfound:; // tomb1 has the first slot we can store into
687687
dic->bloc.emptyn=emptynxt; // save new root of empty chain
688688
emptynxt=HDECEMPTY(hval); WRHASH1234(emptynxt, hsz>>56, &hashtbl[tomb1*(hsz>>56)]) // convert empty# to hashslot#; set hashtable to point to new kv (skipping over reserved hashslot#s)
689689
PUTKVNEW(kbase+hval*(kib>>32),k,kib>>32,hsz&(DICFKINDIR<<DICFBASE)); // copy the new key
690-
dic->bloc.cardinality++; // account for the new keys
690+
dic->bloc.cardinality++; // account for the new key
691691
goto copyval;
692692
// fall through...
693693
found:; // hval is the kv slot we compared with, or a new empty kv slot
@@ -1441,6 +1441,7 @@ static INLINE UI8 jtputslotso(DIC *dic,void *k,I n,void *v,I vn,J jt,UI lv,VIRT
14411441
UI emptynxt=_bzhi_u64(*(UI4*)&kbase[(nodex+TREENRES)*(kib>>32)],(nodeb>>16)); // get next in free chain
14421442
if(emptynxt==nodex)goto resize; // if chained to self, that's end of chain, resize
14431443
dic->bloc.emptyn=emptynxt; // set new head of free chain
1444+
++dic->bloc.cardinality; // increment number of keys
14441445
nodex=RDECEMPTY(nodex); // convert empty index to tree-index with LSB=0
14451446
UI parentd=SGNTO0(comp); // parent's direction
14461447
WLC(nodex,0,0) WR(nodex,0) // new node is empty red
@@ -1616,6 +1617,7 @@ static INLINE UI8 jtdelslotso(DIC *dic,void *k,I n,J jt,UI lv,VIRT virt,B *zv){I
16161617
DELKV(kbasei+(emptyx+TREENRES)*(kib>>32),kib>>32,nodeb&(DICFKINDIR<<8)) DELKV(vbase+emptyx*vb,vb,nodeb&(DICFVINDIR<<8)) // if k/v is indirect, free it & clear to 0
16171618
I t=dic->bloc.emptyn; WRHASH1234(t, nodeb>>19, &kbasei[(emptyx+TREENRES)*(kib>>32)]) // chain old free chain from new deletion
16181619
dic->bloc.emptyn=emptyx; // set new head of chain
1620+
--dic->bloc.cardinality; // remove deleted key from key count
16191621

16201622
I child=(nodexlc|nodexr)&~1; // the one child, if not 0
16211623
if(child){ // is there a child?
@@ -1798,5 +1800,17 @@ DF2(jtdicempties){F12IP;
17981800
RETF(z)
17991801
}
18001802

1803+
// x 16!:_8 dic return dic stats
1804+
DF2(jtdicstats){F12IP;A z;
1805+
ARGCHK2(a,w)
1806+
DIC *dic=(DIC*)w;
1807+
I type; RE(type=i0(a)) // get the stat arg
1808+
switch(type){
1809+
case 0: z=sc(dic->bloc.cardinality); break; // nkeys
1810+
default: ASSERT(0,EVDOMAIN)
1811+
}
1812+
RETF(z);
1813+
}
1814+
18011815

18021816
#endif

0 commit comments

Comments
 (0)