Skip to content

adjacent behavior #2

Description

@Becheler

Hi again! 🌱
I'm trying to understand what the code relative to adjacent matrix does.

From what I understand (telll me if I'm wrong), you have two different behaviors/implementations that are decided based on a condition on the number of nodes in the graph, so you can

  • compress everything in one big vector if it fits in memory
  • or dispatch it across a vector of vectors (int**) if it does not. Am i correct?

If this is the case, then I do not understand how the rest of the code works:

  • int **adj; // adj[x] - adjacency list of node x is supposed to be a vector of vector (2 dimensions)
  • int *adj_matrix; // compressed adjacency matrix is supposed to be the 1D representation of the same data (?)
  • bool (*adjacent)(int, int); this is a pointer on a function so you can switch execution at runtime
  • bool adjacent_list(int x, int y) { return binary_search(adj[x], adj[x] + deg[x], y); } this is the behavior that goes with the 2D implementation (adj)
  • bool adjacent_matrix(int x, int y) { return adj_matrix[(x * n + y) / adj_chunk] & (1 << ((x * n + y) % adj_chunk)); } is the behavior that goes with the 1D representation (adj_matrix)

That is what I could put together, but there are few things I do not understand:

  1. what does the function adjacent_matrix(int, int) actually do?
  2. did the adj vs adj_matrix names get swapped by inadvertence? I would expect adj to be 1D, adj_matrix to be 2D, but it seems to be the reverse in the code?
  3. what is adj_matrix used for? The big algorithm defined in count() seems to access adjacency data uniquely through a call to adj[x][y], what would work only for the 2D representation.

I guess I'm missing a bunch of things! That's a big algo 😉 👏🏽

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions