Comments (2)
Hi!
Yes, the per-match callback allows you to stop execution. Note though, that aggregation happens asynchronously, and Peregrine usually matches pretty fast, so odds are that you'll match much more than you wanted.
If you don't need to write to disk:
uint32_t topK = 1000;
const auto process = [topK](auto &&handle, auto &&match)
{
uint64_t read = handle.read_value(match.pattern);
if (read >= topK)
{
handle.stop();
}
else
{
handle.map(match.pattern, 1);
uint64_t read = handle.read_value(match.pattern);
}
};
auto results = Peregrine::match<Peregrine::Pattern, uint64_t, Peregrine::ON_THE_FLY, Peregrine::STOPPABLE>(data_graph_name, patterns, nthreads, process);
for (const auto &[pattern, count] : results)
{
std::cout << pattern << ": " << count << std::endl;
}
If you want to write the matches to disk, this should do the trick:
uint32_t topK = 1000;
const auto process = [topK](auto &&handle, auto &&match)
{
uint64_t read = handle.read_value(match.pattern);
if (read >= topK)
{
handle.stop();
}
else
{
handle.map(match.pattern, 1);
handle.template output<Peregrine::CSV>(match.mapping); // this writes out matches
uint64_t read = handle.read_value(match.pattern);
}
};
auto results = Peregrine::output<Peregrine::Pattern, uint64_t, Peregrine::ON_THE_FLY, Peregrine::STOPPABLE>(data_graph_name, patterns, nthreads, process);
for (const auto &[pattern, count, path] : results)
{
std::cout << pattern << ": " << count << std::endl;
}
Let me know if you have other questions!
from peregrine.
Thanks!
from peregrine.
Related Issues (19)
- compilation error with TBB HOT 9
- segmentation fault when converting simple input & seemingly incorrect FSM results HOT 6
- Way to output found embeddings? HOT 2
- Unable to compile on MacOS HOT 2
- compile error with libtbb.so.2 HOT 3
- About partial order、matching orders HOT 2
- Unable to compile
- How to make `SmallGraph` into a file
- About the Experimental Dataset HOT 1
- About the dataset HOT 2
- Understanding output HOT 1
- Extending Multi Label Functionality HOT 1
- A question about subgraph match HOT 4
- TBB compiled with gcc 4.7 HOT 1
- Minor Documentation Issue/Enhancement Request
- Unable to compile Peregrine on Ubuntu 16.04 HOT 2
- Wrong output and different results using the data converter HOT 4
- Question - newer algorithm identification and improvements? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from peregrine.