Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/eliahkagan/graph

C# local functions example: graph DFS
https://github.com/eliahkagan/graph

Last synced: about 24 hours ago
JSON representation

C# local functions example: graph DFS

Awesome Lists containing this project

README

        

# Graph - C# local functions example: graph DFS

This is an example of local functions in C#, showing a use in implementing
depth-first traversal of a directed graph.

## Contents

`GraphBasic/Program.cs` (or `graph-basic.linq`) is the clearer example.

`Graph/Program.cs` (or `graph.linq`) shows it with a `Graph` class.

## Notes

If one implements `VerticesReachableFrom` as part of one’s `Graph` class,
one could still benefit from using a local function to capture the visitation
list and results sink. But I figured the example was more compelling this way.

(Also, there is a design argument for implementing `VerticesReachableFrom` in
such a way that a bug in it cannot cause any invariant of `Graph` to be
violated.)

## License

The contents of this repository were written in 2020 by Eliah Kagan (with minor
updates in 2021 and 2023). They are offered under
[0BSD](https://spdx.org/licenses/0BSD.html), a [“public-domain
equivalent”](https://en.wikipedia.org/wiki/Public-domain-equivalent_license)
license. See [**`LICENSE`**](LICENSE).

## See also

`GraphBasic/Program.cs` and `Graph/Program.cs` may also be viewed in the gist
[C# local functions
example](https://gist.github.com/EliahKagan/ca7277a9a20e5631af7ee6a222ecd443),
where they are named `GraphBasic.cs` and `Graph.cs`, respectively.