High Performance Streams Based on Coroutine TS ⚡

Overview

Conduit

Travis Godbolt

Lazy High Performance Streams using Coroutine TS

Conduit is a utility library for building and transforming, ranges and lazy (infinite) iterable sequences.

Conduit's goals are:

  • 🎨 Expressivity
  • 🎶 Composability
  • 🏃 Performance

These are attained by adopting a monadic interface that leverages zero-cost abstractions.

Install

Download the header-only library bundle from the releases page.

If you are using Buckaroo:

buckaroo add github.com/LoopPerfect/conduit@branch=master

Build

To fetch dependencies (only required for testing and benchmarks):

buckaroo install

To build the library:

buck build :conduit

To run the examples:

buck run examples/primes
buck run examples/fibonacci
# etc...

To run the tests:

buck test //...

Examples

Use co_yield to define a coroutine and transform it using high-level operators.

using namespace std;
using namespace conduit;
using namespace conduit::operators;

auto fib = []() -> seq<int> {
  auto a = 0; 
  auto b = 1;
  while ( true ) {
    co_yield a;
    tie(a, b) = tuple{a + b, a};
  }
};

auto items = fib() 
  >> take(5)
  >> zipWith(range, [](auto x, auto y) { 
    return tuple{x, y};
  });

int vals[] = { 0, 1, 1, 2, 3, 5 };

for(auto [i, n] : items) {
  EXPECT_EQ(vals[i], n);
}

Construct elaborate algorithms using higher order operators:

#define RET(X) { return X; }

// sieve of eratosthenes
auto primes = [] {
  return range()
    >> map([](auto i) RET(3+i*2) ) // create a seqence of odd nums > 2
    >> flatMap([primes = vector<int>()](auto c) mutable RET ( 
      primes // divide each candidate by the primes we encountered
        >> find([c](auto p) RET (c % p == 0)) // search and stop if divisible
        >> count() // find yields at most 1 element, count how many we got (starts with zero)
        >> orElse(just(c)) // if we didn't find any, its a prime. yield it
        >> find([](auto x) RET (x)) // filter out zeros yielded by find+count or take prime
        >> forEach([&](auto p) {
          primes.push_back(p);  // update list of primes
        }) // Note: lifetime of primes-vector is bound to the coroutine  
    )) >> startsWith(just(2)); // two is the only even prime
};

Support

Currently only clang-7 with -fcoroutines-ts is supported.

MSVC support should be added in the near future.

Contributions Welcome!

Head over to our issue tracker to get involved in Conduit's development.

You might also like...
PHP Encoder, protect PHP scripts in PHP 8 and PHP 7, High Performance, Compitable with X86_64, MIPS, ARM platform and Ubuntu/Centos/OpenWRT system.

What's FRICC2? FRICC2 is a PHP Script encryption tool. When you are developing a commercial software using PHP, the script can be distributed as encry

Diff Match Patch is a high-performance library in multiple languages that manipulates plain text.

The Diff Match and Patch libraries offer robust algorithms to perform the operations required for synchronizing plain text. Diff: Compare two blocks o

Flexible, portable, high-performance bit fields C++ library. unsigned a:13 becomes F13 a;

C-plus-plus-library-bit-fields Flexible, portible, high-performance bit fields C++ library. The bit fields are specified with a dummy structure where

Real Time, High performance BOT detection and protection
Real Time, High performance BOT detection and protection

REAL-TIME BOT PROTECTION CHALLENGE IronFox https://innovera.ir IronFox is a real-time and high performance bot protection, that using Nginx as a reve

Cloud-native high-performance edge/middle/service proxy
Cloud-native high-performance edge/middle/service proxy

Cloud-native high-performance edge/middle/service proxy Envoy is hosted by the Cloud Native Computing Foundation (CNCF). If you are a company that wan

Emergency alert and tracer for realtime high-performance computing app (work in progress, currently supported env is only Linux x86-64).

HPC Emerg Emergency alert and tracer for realtime high-performance computing app (work in progress, currently supported env is only Linux x86-64). Exa

A high performance, shared memory, lock free, cross platform, single file, no dependencies, C++11 key-value store
A high performance, shared memory, lock free, cross platform, single file, no dependencies, C++11 key-value store

SimDB A high performance, shared memory, lock free, cross platform, single file, no dependencies, C++11 key-value store. SimDB is part of LAVA (Live A

A high-performance MongoDB driver for C

mongo-c-driver About mongo-c-driver is a project that includes two libraries: libmongoc, a client library written in C for MongoDB. libbson, a library

Kit: a magical, high performance programming language, designed for game development
Kit: a magical, high performance programming language, designed for game development

Kit: a magical, high performance programming language, designed for game development

Comments
  • Add terminating allocator

    Add terminating allocator

    Should terminate when attempting to allocate a coroutine on the heap. This will enable us to write tests that prove that the operators and algorithms are optimizable.

    opened by nikhedonia 0
  • Add more examples

    Add more examples

    We need more examples to smoke test the compiler. Anyone fancy to implement some Range-V3 examples?

    https://github.com/ericniebler/range-v3/blob/master/example/calendar.cpp

    Benchmarking facilities are following soon.

    help wanted good first issue 
    opened by nikhedonia 0
Owner
LoopPerfect
C++ Dev Tools Company
LoopPerfect
This is a simple filter that will block any attempt to access streams beginning with

Triggering the notification only requires that you visit a particular path on an NTFS volume.

OSR Open Systems Resources, Inc. 73 Nov 1, 2022
The purpose of these streams is to be educational and entertaining for viewers to learn about systems architecture, reverse engineering, software security, etc., and NOT to encourage nor endorse malicious game hacking.

Memestream This repository holds the code that I develop during my live game "modding" ?? sessions. When I stream, I like to speedrun making a success

Stephen Tong 28 Jul 6, 2022
John Walker 24 Dec 15, 2022
V wrapper of Edubart's minicoro - A cross-platform coroutine library

minicoro.v WIP. See issues. Not a fork! This isn't a fork of edubart's minicoro [https://github.com/edubart/minicoro] but a wrapper built from the gro

Steven Gay 12 Dec 2, 2022
Visualization Library is a C++ middleware for high-performance 2D and 3D graphics applications based on OpenGL 1.x-4.x supporting Windows, Linux and Mac OS X.

Visualization Library 2.2 Gallery About Visualization Library is a C++ middleware for high-performance 2D and 3D graphics applications based on the in

Michele 313 Nov 8, 2022
An AI for playing NES Tetris at a high level. Based primarily on search & heuristic, with high quality board evaluation through value iteration.

StackRabbit An AI that plays NES Tetris at a high level. Primarily based on search & heuristic, with high-quality board eval through value iteration.

Greg Cannon 244 Jan 5, 2023
High performance C++11 signals

High performance C++11 signals See Performance of a C++11 Signal System for the original source code, as well as performance measurements compared to

Lars Pensjö 145 Nov 28, 2022
A C++11 large integer library with effective high performance, simplistic in nature and also clean in the eyes.

BigIntegerCPP BigIntegerCPP is a C++11 port of large integer library used in CryptoLib4Pascal. It allows mostly parsing of numbers as strings in diffe

Telepati 26 Dec 22, 2022
high performance C++20 implementation of std::variant

A minimal compile-time overhead, C++20 implementation of std::variant. Fully standard conforming with a couple of documented differences.

null 37 Nov 22, 2022
Convenient, high-performance RGB color and position control for console output

Oof (omnipotent output friend) It's common for C++ programs to write output to the console. But consoles are far more capable than what they are usual

Sebastian Werhausen 776 Dec 27, 2022