Releases: datavis-tech/graph-data-structure
Release 4.1.0
What's Changed
- fix:
getEdgeProperties
may returnundefined
if the edge doesn't exists by @JesusTheHun in #94 - feat: add
props
to theshouldFollow
opts, which contain the edge properties by @JesusTheHun in #95 - Update README.md by @curran in #91
Full Changelog: v4.0.0...v4.1.0
v4.0.0
Many thanks to @JesusTheHun for massively refactoring the library and API in this major version!
The following details come from #81:
Breaking changes :
Graph
is now a class, so it is instantiated withnew Graph()
instead ofGraph()
.Graph.adjacent()
now returns aSet<Node>
orundefined
if the node is not found.Graph.nodes()
is no longer available. A propertynodes: Set<Node>
is now exposed.Graph.serialize()
is no longer available. A standalone functionserializeGraph
is available instead.Graph.deserialize()
is no longer available. A standalone functiondeserializeGraph
is available instead.Graph.hasCycle()
is no longer available. A standalone functionhasCycle
is available instead.- All algorithm methods (i.e.
graph.topologicalSort()
are no longer available. A standalone function is available for each of them. - The
shortestPath
algorithm now returns an object{ nodes: Node[], weight: number }
instead of an augmented array.
Internal changes :
- The project now uses a composition pattern. Closes #18
- Native data structure
Map
andSet
are used instead of records and arrays. Closes #27 - Nodes are now references by their instance instead of their
id
property. - The tests have been migrated to
vitest
in order to be able to write tests in TypeScript without troubles. - Additional tests for types input and output have been written.
- The library is now bundled using rollup. The current solution does not support the export of types coming from type-only files. In addition, both
.d.cts
and.d.mts
declaration files are now distributed.
Features :
- Nodes can now be anything, not just string. Closes #51, closes #38
- New functions
getNode
,getFirstNode
,findNodes
to help you retrieve node references when they are objects. - Edge can now have properties. Closes #80
- Algorithm
depthFirstSearch
now accepts a functionshouldFollow
as an option, to conditionally follow an edge. Graph
now accept 2 generics to define the type of the nodes and edge properties.- The graph types are inferred from
deserializeGraph()
and the serialization type carries the types with it.
const g = new Graph<{ id: string }, { type: string }>();
// Good ✅
g.addNode({ id: "abcdef" });
g.setEdgeProperties(source, target, { type: 'foo' });
// Bad ❌ TS Error
g.addNode({ id: 1 });
g.setEdgeProperties(source, target, { label: 'wrong prop name' });
const node = g.nodes();
// ^? { id: string }[]
const props = g.getEdgeProperties(source, target);
// ^? { type: string }
Migration
Serialization
-const serialized = Graph().serialize();
+const serialized = serializeGraph(graph);
-const graph = Graph().deserialize(serialized);
+const graph = deserializeGraph(serialized);
Algorithms
-const sorted = graph.topologicalSort();
+const sorted = topologicalSort(graph);
-const path = graph.shortestPath();
-const nodes = path;
-const weight = path.weight;
+const { nodes, weight } = shortestPath(graph);
What's Changed
- New major version proposal by @JesusTheHun in #81
- Wrap up details for new major version release by @JesusTheHun in #87
- fix: update README.md example for node by @amopitt in #77
- Upgrade dependencies, run prettier by @curran in #83
- Upgrade dependencies by @curran in #89
New Contributors
- @amopitt made their first contribution in #77
- @JesusTheHun made their first contribution in #81
Full Changelog: v3.5.0...v4.0.0
v3.5.0
Release 3.4.0
Release 3.3.0
Export types, update dependencies
Release 3.1.1
Release 3.1.0
Release 3.0.0
Many thanks to @TimMikeladze for the contributions in #56 !
Marking this a major release as the build tools have changed, which may impact downstream builds (but most likely will not). No API changes here.
Fix optional argument for topological sort, target ES6
PR: Fix optional argument for topological sort, target ES6. Thanks to @CrispyBacon1999 for this contribution!
I'm making this a major version bump because the target language for the JS build has changed from ES5 (var
) to ES6 (const
, let
). While for the most part this will not cause breakages, there's a slight possibility that it would, in cases where downstream products run in an environment that does not support ES6.