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

feat: Add acyclic and tred support #211

Merged
merged 1 commit into from
Jan 17, 2024

Conversation

GordonSmith
Copy link
Member

Fixes #210

{
if (agtail(e) != aghead(e))
rv++;
FILE *outFile = fopen("tmp.dot", "w");
Copy link

@Smattr Smattr Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you not want to (1) use a getenv("TMPDIR") || "/tmp" prefix, (2) use mkstemp or something to ensure parallel executions won’t interfere with each other, and (2) check for failure here?

Alternative to using a temporary file, if this only runs on !Windows, you could do this entirely in memory with open_memstream.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI neither of these are really a concern in WebAssembly as the files end up in memory anyway (and parallel execution will only happen with separate instances).
I will tidy up into a convenience class anyway as this is code is getting reproduced a few times now...

@@ -155,24 +156,90 @@ export class Graphviz {
return retVal;
}

/**
* acyclic is a filter that takes a directed graph as input and outputs a copy of the graph with sufficient edges reversed to make the graph acyclic. The reversed edge inherits all of the attributes of the original edge. The optional file argument specifies where the the input graph is stored; by default.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/the the/the

* @param dotSource Required - graph definition in [DOT](https://graphviz.gitlab.io/doc/info/lang.html) language
* @param doWrite Enable output is produced, though the return value will indicate whether the graph is acyclic or not.
* @param verbose Print information about whether the file is acyclic, has a cycle or is undirected.
* @returns `{ acyclic: boolean, num_rev: number, outFile: string }` Boolean will be true if a cycle was found, as well as.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: double space. Though it actually looks like there are more words missing here.

Refactor graphviz to common up buffer usage
Fixed typos in javadoc
Added some simple tests for async and tred
Fixed error reporting for unflatten

Fixes hpcc-systems#210

Signed-off-by: Gordon Smith <GordonJSmith@gmail.com>
@GordonSmith GordonSmith merged commit eeab5db into hpcc-systems:trunk Jan 17, 2024
5 checks passed
@GordonSmith GordonSmith deleted the GV_10 branch January 17, 2024 08:11
Copy link

@Smattr Smattr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not an expert in most of this stuff, but in general LGTM!

Comment on lines +22 to +24
public:
TempFileBuffer();
~TempFileBuffer();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to = delete the copy/move constructor/assignment for this class, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True.


#include <string>

class StringBuffer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand the intent of this class. Why not just use a std::string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a naming issue (StringAdapter might be better), but this allows the IDL generated "glue" code to return a const char * directly, without having to declare an explicit const char * member.

class TempFileBuffer
{
private:
FILE *filePointer = nullptr;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include <cstdio>?

@@ -1,10 +1,9 @@
#include <string>
#include "util.hpp"

class Graphviz
{
private:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think you could also remove this line.

if (filePointer != nullptr)
{
std::rewind(filePointer);
char buffer[256];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe you want to use BUFSIZ for the size here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be able to remove the buff and loop altogether...

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

Successfully merging this pull request may close these issues.

Transitive reduction filter for directed graphs - Graphviz
2 participants