Skip to content

Commit

Permalink
Added print functions for the strict dyad hashmaps.
Browse files Browse the repository at this point in the history
  • Loading branch information
krivit committed Apr 12, 2024
1 parent e8d03bd commit 60c72dd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions inst/include/ergm_dyad_hashmap_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@

/* Utility function declarations. */
void PrintDyadMapUInt(StoreDyadMapUInt *h);
void PrintStrictDyadMapUInt(StoreStrictDyadMapUInt *h);
void PrintDyadSet(StoreDyadSet *h);
void PrintStrictDyadSet(StoreStrictDyadSet *h);
StoreDyadSet *NetworkToDyadSet(Network *nwp);
StoreStrictDyadSet *NetworkToStrictDyadSet(Network *nwp);

#endif // _ERGM_DYAD_HASHMAP_H_
32 changes: 32 additions & 0 deletions src/ergm_dyad_hashmap_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ void PrintDyadMapUInt(StoreDyadMapUInt *h){
}
}

/* Print the contents of a khash table mapping dyads to unsigned
integers. Useful for debugging. */
void PrintStrictDyadMapUInt(StoreStrictDyadMapUInt *h){
for(khiter_t i = kh_begin(h); i!=kh_end(h); ++i){
if(kh_exist(h, i)){
TailHead k = kh_key(h, i);
unsigned int v = kh_val(h, i);
Rprintf("(%d,%d)->%u\n",k.tail,k.head,v);
}
}
}

/* Print the contents of a khash set of dyads. Useful for debugging. */
void PrintDyadSet(StoreDyadSet *h){
for(khiter_t i = kh_begin(h); i!=kh_end(h); ++i){
Expand All @@ -34,6 +46,17 @@ void PrintDyadSet(StoreDyadSet *h){
Rprintf("\n");
}

/* Print the contents of a khash set of dyads. Useful for debugging. */
void PrintStrictDyadSet(StoreStrictDyadSet *h){
for(khiter_t i = kh_begin(h); i!=kh_end(h); ++i){
if(kh_exist(h, i)){
TailHead k = kh_key(h, i);
Rprintf("(%d,%d) ",k.tail,k.head);
}
}
Rprintf("\n");
}

/* Copy network to a khash set of dyads. */
StoreDyadSet *NetworkToDyadSet(Network *nwp){
StoreDyadSet *h = kh_init(DyadSet);
Expand All @@ -44,3 +67,12 @@ StoreDyadSet *NetworkToDyadSet(Network *nwp){
});
return h;
}

StoreStrictDyadSet *NetworkToStrictDyadSet(Network *nwp){
StoreStrictDyadSet *h = kh_init(StrictDyadSet);

EXEC_THROUGH_NET_EDGES(tail, head, e, {
kh_put(StrictDyadSet, h, TH(tail,head), NULL);
});
return h;
}

0 comments on commit 60c72dd

Please sign in to comment.