Skip to content

Commit

Permalink
Adjacency list optimizations (#9444)
Browse files Browse the repository at this point in the history
* Parameterize AdjacencyList

* perf: reduce memory overhead in AdjacencyList

Previously, we were allocating extra space for 'buckets'
to accommodate hash collisions, but this turns out to waste a lot of space
in large graphs.

Additionally, we are no longer allocating space for nodes ahead of time;
now, the nodes array will grow on demand, as edges are added.

* refactor: extract edge linking behavior from addEdges method

This unlocks the ability to resize without creating a new intermediary AdjacencyList.

* fix: improve map capacity overflow detection

* fix: resizing computations

* Remove loadFactor

* fix: node resizing

* fix: avg collisions calculation

* Rename capacity to initialCapacity

* fix tests

* fix: remove erroneous assertion

The (incorrect) assumption was that there should be the same node record count
after a resize of edges, but this is not necessarily the case; if there were
deleted edges before the resize, then there may be node records that will
also be deleted (by virtue of no longer having any edges connected to them)
as part of the resize.

* Enforce assumption that linked edge types must match

* Add docs

* Update AdjacencyList.md

* Update AdjacencyList.md

* Update AdjacencyList.md

* Refactor link results to an enum

* Update AdjacencyList.md
  • Loading branch information
lettertwo authored Feb 13, 2024
1 parent e14784d commit 2215d36
Show file tree
Hide file tree
Showing 3 changed files with 1,384 additions and 207 deletions.
Loading

0 comments on commit 2215d36

Please sign in to comment.