Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds depth-first search and breadth-first search #40

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

daniel-j-h
Copy link
Member

This adds an experimental library API for searchers: depth-first search and breadth-first search.

The current API proposal I ended up with is as follows

// created a new search context that can be re-used across multiple searches
tinygraph_dfs_s ctx = tinygraph_dfs_construct(graph);

// for this search start at node 0
tinygraph_dfs_set_start(ctx, 0);

// step through the search space one by one
while (!tinygraph_dfs_is_done(ctx)) {
    uint32_t next = tinygraph_dfs_step(ctx);
    ..
}

// to re-use the same context, clear it and then step through another search
tinygraph_dfs_clear(ctx);

The main idea is that the search context can keep internal state (stack or queue and a bitset) and cache their construction and allocation between multiple searches. For example for all subsequent searches after the very first one we can simply re-use the allocated bitset and can re-use the stack or queue's internal allocations.

Open questions

  • Should clear and set_start be two separate functions or should it just be one function that automatically clears the internal state whenever a new start node is set? What are the pros and cons of this design decision?
  • Should we provide more customization at this point already e.g. a max depth at which to stop the search?
  • Should the search stepping only return newly discovered nodes or rather return (s, t) node tuples so that the user has more information than just the new node?
  • How would an easy interface look like so that we can wrap it e.g. into a Python iterator interface for ease of use?

Once we get this API into the standard libtinygraph.h header we better have a solid interface figured out. The alternative is adding a separate experimental header just for searches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant