From aa52a45813cc53ea345046388f19863ee95cf80f Mon Sep 17 00:00:00 2001 From: Alex Sweeney Date: Mon, 25 Apr 2022 22:42:48 -0500 Subject: [PATCH] clean up readme --- README.md | 144 ++++++++++++++++++++++++++++++++------------------- build.gradle | 2 + 2 files changed, 93 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 489298c..f7c2079 100644 --- a/README.md +++ b/README.md @@ -1,83 +1,91 @@ -# A DAG in Java +# A `Dag` in Java -## How do I get it? - -### Gradle package from GitHub Packages - -```gradle -repositories { - mavenCentral() - maven { - url = uri('https://maven.pkg.github.com/ajs1998/Dag') - credentials { - username = 'ajs1998' - // This is a PAT (Personal Access Token) that only has permission to read/download public GitHub Packages. - // This is not the actual password for the account. - password = {YOUR GITHUB PAT} - } - } -} -``` - -```gradle -dependencies { - implementation 'me.alexjs:dag:1.10' -} -``` - -You need to create a GitHub Personal Access Token (PAT) to be able to -download GitHub Packages. The token only needs the `read:packages` permission to work. - -### Maven Central package - -Coming soon +## What is it? ## What can I do with it? +### Add nodes with (parent, child) relationships to the DAG + ```java Dag dag = new HashDag<>(); -// Add nodes with (parent, child) relationships to the DAG dag.put("Dorothy", "Shelby"); dag.put("Shelby", "Alex"); dag.put("Joe", "Alex"); +``` -// Add individual nodes to the DAG +### Add individual nodes to the DAG + +```java dag.add("Clare"); dag.add("Sarah"); +``` -// Find a topologically sorted list of the nodes -// Ex: ["Sarah", "Clare", "Dorothy", "Joe", "Shelby", "Alex"] +### Find a topologically sorted list of the nodes + +```java List sorted = dag.sort(); +``` -// Find the root nodes of the DAG -// Ex: ["Dorothy", "Joe", "Clare", "Sarah"] -Set roots= dag.getRoots(); +> `["Sarah", "Clare", "Dorothy", "Joe", "Shelby", "Alex"]` -// Find the leaf nodes of the DAG -// Ex: ["Alex", "Clare", "Sarah"] +### Find the root nodes of the DAG + +```java +Set roots = dag.getRoots(); +``` + +> `["Dorothy", "Joe", "Clare", "Sarah"]` + +### Find the leaf nodes of the DAG + +```java Set leaves = dag.getLeaves(); +``` + +> `["Alex", "Clare", "Sarah"]` -// Find the parents of a node -// Ex: ["Joe", "Shelby"] +### Find the parents of a node + +```java Set parents = dag.getParents("Alex"); +``` -// Find the children of a node -// Ex: ["Shelby"] +> `["Joe", "Shelby"]` + +### Find the children of a node + +```java Set children = dag.getChildren("Dorothy"); +``` + +> `["Shelby"]` + +### Find the ancestors of a node -// Find the ancestors of a node -// Ex: ["Joe", "Shelby", "Dorothy"] +```java Set ancestors = dag.getAncestors("Alex"); +``` + +> `["Joe", "Shelby", "Dorothy"]` -// Find the descendants of a node -// Ex: ["Shelby", "Alex"] +### Find the descendants of a node + +```java Set descendants = dag.getDescendants("Dorothy"); +``` -// Get the Map representation of the DAG +> `["Shelby", "Alex"]` + +### Get the Map representation of the DAG + +```java Map> map = dag.toMap(); +``` + +### Create a shallow copy -// Create a shallow copy +```java Dag copy = dag.clone(); ``` @@ -92,10 +100,40 @@ List result = new LinkedList<>(); DagUtil.traverse(dag, i -> result.add(i), executorService); ``` +## How do I get it? + +### Gradle package from GitHub Packages + +```gradle +repositories { + mavenCentral() + maven { + url = uri('https://maven.pkg.github.com/ajs1998/Dag') + credentials { + username = {YOUR GITHUB USERNAME} + // This is a PAT (Personal Access Token) that only has permission to read/download public GitHub Packages. + // This is not the actual password for the account. + password = {YOUR GITHUB PAT} + } + } +} +``` + +```gradle +dependencies { + implementation 'me.alexjs:dag:1.0.0' +} +``` + +You need to create a GitHub Personal Access Token (PAT) to be able to +download GitHub Packages. The token only needs the `read:packages` permission to work. + +### Maven Central package + +Coming soon + ## Notes - Flexible `Dag` interface so you can write your own implementation - 100% test coverage - 100% Javadoc coverage -- I recommend using at least version `1.10`. Previous versions had little documentation, less test coverage, and fewer - features diff --git a/build.gradle b/build.gradle index 8836483..7d3fa3c 100644 --- a/build.gradle +++ b/build.gradle @@ -10,8 +10,10 @@ repositories { } dependencies { + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2' + } test {