alid ~main

'cached' that stores elements of InputRanges as ForwardRanges efficiently, and other modules


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:


This package provides sub packages which can be used individually:

alid:blockreusable - Reusable block of elements that can emplace and moveEmplace

alid:cached - Range algorithm to cache elements of InputRanges and present them as ForwardRanges with opIndex

alid:circularblocks - Expanding circular buffer that uses array of blocks of memory

alid:errornogc - Defining and throwing of Error subclasses inside @nogc code

alid:test - Unit test helpers

Introduction

This repository is a collection of D modules written by Ali Çehreli.

Name

The package name alid is a combination of "Ali" and "D".

History

It started with cached which was based on an old idea of Ali's that rested for more than ten years. Ali decided to revisit the idea when a piece of D code--written by Janis, a friend and colleague--produced surprising results. The surprises were due to side effects in a generator function similar to the map lambda in the following code:

    auto r = iota(n)
             .map!((i) {
                     arr ~= i;     // <-- A side effect (adds to an array)
                     return i;
                 })
             .filter!(i => true);  // <-- The side effect is repeated

Every access to the generated "element" down the execution chain repeats the side effect, adding one more element to the array in the code above.

Features

cached

cached is for executing elements only once while not holding on to old elements for too long; the elements that have been popFronted by all ranges are dropped from the cache according some heuristics.

cached was the main topic of Ali's DConf 2022 lightning talk.

It caches the elements of its source range to ensure that the side effect of each generated element is applied only once:

    auto r = iota(n)
             .map!((i) {
                     arr ~= i;     // <-- A side effect (adds to an array)
                     return i;
                 })
             .cached               // <-- Caches the generated elements
             .filter!(i => true);  // <-- The side effect is NOT repeated

cached provides a ForwardRange interface as well as random access to elements even when the source range is an InputRange.

circularblocks

circularblocks was written for storing range elements of cached. It can be used independently.

blockreusable

blockreusable was written as storage blocks for circularblocks. It can be used independently.

errornogc

errornogc was needed for throwing Errors from @nogc code. It can be used independently.

test

test contains some helper utilities for unit testing.

Authors:
  • Ali Çehreli
Sub packages:
alid:blockreusable, alid:cached, alid:circularblocks, alid:errornogc, alid:test
Dependencies:
none
Versions:
0.1.6 2022-Oct-04
0.1.5 2022-Sep-23
0.1.4 2022-Sep-15
0.1.3 2022-Sep-15
0.1.2 2022-Sep-14
Show all 8 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 24 downloads total

Score:
0.7
Short URL:
alid.dub.pm