Skip to content

Commit

Permalink
Added a function UnsrtELToHashEL() that converts an existing UnsrtEL …
Browse files Browse the repository at this point in the history
…to a HashEL by embedding it in HashEL's data structure.
  • Loading branch information
krivit committed Feb 5, 2024
1 parent a3c0e2e commit b05128c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions inst/include/ergm_hash_edgelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,31 @@ typedef struct {
StoreDyadMapUInt *hash;
} HashEL;

static inline HashEL *HashELInitialize(unsigned int nedges, Vertex *tails, Vertex *heads, Rboolean copy, Rboolean directed) {
/* Embed an existing UnsrtEL into a HashEL. */
static inline HashEL *UnsrtELIntoHashEL(UnsrtEL *el, Rboolean directed) {
HashEL *hash = Calloc(1, HashEL);

hash->list = UnsrtELInitialize(nedges, tails, heads, copy);
hash->list = el;

hash->hash = kh_init(DyadMapUInt);
hash->hash->directed = directed;

if(nedges > 0) {
kh_resize(DyadMapUInt, hash->hash, 2*(nedges + 1));
if(el->nedges > 0) {
kh_resize(DyadMapUInt, hash->hash, 2*(el->nedges + 1));

for(unsigned int i = 0; i < nedges; i++) {
kh_set(DyadMapUInt, hash->hash, TH(tails[i], heads[i]), i + 1);
for(unsigned int i = 1; i <= el->nedges; i++) {
kh_set(DyadMapUInt, hash->hash, TH(el->tails[i], el->heads[i]), i);
}
}

return hash;
}

static inline HashEL *HashELInitialize(unsigned int nedges, Vertex *tails, Vertex *heads, Rboolean copy, Rboolean directed) {
UnsrtEL *el = UnsrtELInitialize(nedges, tails, heads, copy);
return UnsrtELIntoHashEL(el, directed);
}

static inline void HashELDestroy(HashEL *hash) {
kh_destroy(DyadMapUInt, hash->hash);
UnsrtELDestroy(hash->list);
Expand Down

0 comments on commit b05128c

Please sign in to comment.