Skip to content

Commit 7152ba9

Browse files
committed
Merge branch 'master' of https://github.com/libmir/mir-algorithm
2 parents 0860023 + 9df51fb commit 7152ba9

File tree

28 files changed

+1535
-269
lines changed

28 files changed

+1535
-269
lines changed

.github/workflows/ci.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
workflow_dispatch:
11+
# allow this workflow to be triggered manually
12+
13+
jobs:
14+
builder:
15+
name: 'Build and test on ${{ matrix.arch }}-${{ matrix.os }}/${{ matrix.dc }}'
16+
runs-on: ${{ matrix.os }}
17+
continue-on-error: ${{ contains(matrix.dc, 'master') || contains(matrix.dc, 'beta') }}
18+
env:
19+
ARCH: ${{ matrix.arch }}
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
dc: [ldc-latest, ldc-beta, dmd-latest, dmd-master, dmd-beta]
24+
os: [ubuntu-latest]
25+
arch: [x86, x86_64]
26+
include:
27+
- dc: ldc-latest
28+
os: macos-latest
29+
arch: x86_64
30+
- dc: dmd-latest
31+
os: macos-latest
32+
arch: x86_64
33+
steps:
34+
- uses: actions/checkout@v2
35+
- uses: dlang-community/setup-dlang@v1.1.0
36+
with:
37+
compiler: ${{ matrix.dc }}
38+
- name: Install multi-lib for 32-bit systems
39+
if: matrix.arch == 'x86'
40+
run: sudo apt-get install gcc-multilib
41+
- id: build
42+
name: Test building
43+
run: bash -e test_travis.sh
44+
- id: coverage
45+
name: Upload coverage data
46+
run: bash <(curl -s https://codecov.io/bash)
47+
48+

include/mir/interpolate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#pragma once
12

23
namespace mir {
34
namespace interpolate

include/mir/ndslice.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#ifndef MIR_NDSLICE
2+
3+
#define MIR_NDSLICE
4+
15
/**
26
************ Mir-Algorithm ************
37
@@ -8,11 +12,6 @@ License: $(HTTP www.apache.org/licenses/LICENSE-2.0, Apache-2.0)
812
Copyright: 2020 Ilya Yaroshenko, Kaleidic Associates Advisory Limited, Symmetry Investments
913
Authors: Ilya Yaroshenko
1014
*/
11-
12-
#ifndef MIR_NDSLICE
13-
14-
#define MIR_NDSLICE
15-
1615
#include <cstddef>
1716
#include <cstdint>
1817
#include <stdexcept>

include/mir/small_string.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#pragma once
12
// Self contained generic small string implementaton.
23
#include <cstring>
34
#include <cstddef>

index.d

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,26 @@ $(BOOKTABLE ,
1111
$(TH Description)
1212
)
1313
$(LEADINGROW Accessories)
14+
$(TR $(TDNW $(MREF mir,algebraic_alias,ion)) $(TD Mutable Amazon's Ion value))
1415
$(TR $(TDNW $(MREF mir,algebraic_alias,json)) $(TD Mutable JSON value))
16+
$(TR $(TDNW $(MREF mir,annotated)) $(TD Mutable generic Annotated value))
1517
$(TR $(TDNW $(MREF mir,array,allocation)) $(TD `std.array` reworked for Mir))
1618
$(TR $(TDNW $(MREF mir,format)) $(TD @nogc Formatting Utilities))
19+
$(TR $(TDNW $(MREF mir,lob)) $(TD Binar and Char Large Objects ))
1720
$(TR $(TDNW $(MREF mir,parse)) $(TD @nogc Parsing Utilities))
1821
$(TR $(TDNW $(MREF mir,range)) $(TD Ranges))
1922
$(TR $(TDNW $(MREF mir,serde)) $(TD Utilities for serialization libraries ))
2023
$(TR $(TDNW $(MREF mir,small_array)) $(TD Generic Small Arrays))
2124
$(TR $(TDNW $(MREF mir,small_string)) $(TD Generic Small Strings))
2225
$(TR $(TDNW $(MREF mir,string_map)) $(TD Ordered string-value associative array with fast lookup))
23-
$(TR $(TDNW $(MREF mir,lob)) $(TD Binar and Char Large Objects ))
2426
$(LEADINGROW Date and time)
2527
$(TR $(TDNW $(MREF mir,date)) $(TD Fast BetterC Date type with Boost ABI and mangling compatability))
2628
$(TR $(TDNW $(MREF mir,timestamp)) $(TD General purpose timestamp implementation with arbitrary precision ))
2729
$(LEADINGROW NDarrays and Algorithms)
2830
$(TR $(TDNW $(MREF mir,algorithm,iteration)) $(TD Mir & BetterC rework of Phobos.))
2931
$(TR $(TDNW $(MREF mir,algorithm,setops)) $(TD Mir & BetterC rework of Phobos.))
3032
$(TR $(TDNW $(MREF mir,ndslice)★) $(TD Package for ndarrays and iteration algorithms.))
31-
$(TR $(TDNW $(MREF mir,range)) $(TD Additoinal primitive ranges. See also $(MREF mir,ndslice), which contains a lot of range constructos.))
33+
$(TR $(TDNW $(MREF mir,range)) $(TD Additional primitive ranges. See also $(MREF mir,ndslice), which contains a lot of range constructos.))
3234
$(LEADINGROW Math)
3335
$(TR $(TDNW $(MREF mir,interpolate)★) $(TD Interpolation algorithms))
3436
$(TR $(TDNW $(MREF mir,math,numeric)) $(TD Simple numeric algorithms))

meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ subprojects = ['mir-core']
88
has_cpp_headers = true
99

1010
sources_list = [
11+
'mir/algebraic_alias/ion',
1112
'mir/algebraic_alias/json',
1213
'mir/algorithm/iteration',
1314
'mir/algorithm/setops',
15+
'mir/annotated',
1416
'mir/appender',
1517
'mir/array/allocation',
1618
'mir/bignum/decimal',

source/mir/algebraic_alias/ion.d

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/++
2+
$(H1 Mutable Ion value)
3+
4+
This module contains a single alias definition and doesn't provide Ion serialization API.
5+
6+
See_also: Ion library $(MIR_PACKAGE mir-ion)
7+
8+
License: $(HTTP www.apache.org/licenses/LICENSE-2.0, Apache-2.0)
9+
Authors: Ilya Yaroshenko
10+
Macros:
11+
+/
12+
module mir.algebraic_alias.ion;
13+
14+
import mir.algebraic: TaggedVariant, This;
15+
public import mir.annotated: Annotated;
16+
public import mir.lob: Clob, Blob;
17+
public import mir.string_map: StringMap;
18+
public import mir.timestamp: Timestamp;
19+
20+
21+
/++
22+
Definition union for $(LREF IonAlgebraic).
23+
+/
24+
union IonAlgebraicUnion
25+
{
26+
///
27+
typeof(null) null_;
28+
///
29+
bool boolean;
30+
///
31+
long integer;
32+
///
33+
double float_;
34+
///
35+
immutable(char)[] string;
36+
///
37+
Blob blob;
38+
///
39+
Clob clob;
40+
///
41+
Timestamp timestamp;
42+
/// Self alias in array.
43+
This[] array;
44+
/// Self alias in $(MREF mir,string_map).
45+
StringMap!This object;
46+
/// Self alias in $(MREF mir,annotated).
47+
Annotated!This annotations;
48+
}
49+
50+
/++
51+
Ion tagged algebraic alias.
52+
53+
The example below shows only the basic features. Advanced API to work with algebraic types can be found at $(GMREF mir-core, mir,algebraic).
54+
See also $(MREF mir,string_map) - ordered string-value associative array.
55+
+/
56+
alias IonAlgebraic = TaggedVariant!IonAlgebraicUnion;
57+
58+
///
59+
unittest
60+
{
61+
import mir.ndslice.topology: map;
62+
import mir.array.allocation: array;
63+
64+
IonAlgebraic value;
65+
66+
StringMap!IonAlgebraic object;
67+
68+
// Default
69+
assert(value.isNull);
70+
assert(value.kind == IonAlgebraic.Kind.null_);
71+
72+
// Boolean
73+
value = object["bool"] = true;
74+
assert(!value.isNull);
75+
assert(value == true);
76+
assert(value.kind == IonAlgebraic.Kind.boolean);
77+
assert(value.get!bool == true);
78+
assert(value.get!(IonAlgebraic.Kind.boolean) == true);
79+
80+
// Null
81+
value = object["null"] = null;
82+
assert(value.isNull);
83+
assert(value == null);
84+
assert(value.kind == IonAlgebraic.Kind.null_);
85+
assert(value.get!(typeof(null)) == null);
86+
assert(value.get!(IonAlgebraic.Kind.null_) == null);
87+
88+
// String
89+
value = object["string"] = "s";
90+
assert(value.kind == IonAlgebraic.Kind.string);
91+
assert(value == "s");
92+
assert(value.get!string == "s");
93+
assert(value.get!(IonAlgebraic.Kind.string) == "s");
94+
95+
// Integer
96+
value = object["integer"] = 4;
97+
assert(value.kind == IonAlgebraic.Kind.integer);
98+
assert(value == 4);
99+
assert(value != 4.0);
100+
assert(value.get!long == 4);
101+
assert(value.get!(IonAlgebraic.Kind.integer) == 4);
102+
103+
// Float
104+
value = object["float"] = 3.0;
105+
assert(value.kind == IonAlgebraic.Kind.float_);
106+
assert(value != 3);
107+
assert(value == 3.0);
108+
assert(value.get!double == 3.0);
109+
assert(value.get!(IonAlgebraic.Kind.float_) == 3.0);
110+
111+
// Array
112+
IonAlgebraic[] arr = [0, 1, 2, 3, 4].map!IonAlgebraic.array;
113+
114+
value = object["array"] = arr;
115+
assert(value.kind == IonAlgebraic.Kind.array);
116+
assert(value == arr);
117+
assert(value.get!(IonAlgebraic[])[3] == 3);
118+
119+
// Object
120+
assert(object.keys == ["bool", "null", "string", "integer", "float", "array"]);
121+
object.values[0] = "false";
122+
assert(object["bool"] == "false"); // it is a string now
123+
object.remove("bool"); // remove the member
124+
125+
value = object["array"] = object;
126+
assert(value.kind == IonAlgebraic.Kind.object);
127+
assert(value.get!(StringMap!IonAlgebraic).keys is object.keys);
128+
assert(value.get!(StringMap!IonAlgebraic).values is object.values);
129+
130+
IonAlgebraic[string] aa = object.toAA;
131+
object = StringMap!IonAlgebraic(aa);
132+
133+
IonAlgebraic fromAA = ["a" : IonAlgebraic(3), "b" : IonAlgebraic("b")];
134+
assert(fromAA.get!(StringMap!IonAlgebraic)["a"] == 3);
135+
assert(fromAA.get!(StringMap!IonAlgebraic)["b"] == "b");
136+
137+
auto annotated = Annotated!IonAlgebraic(["birthday"], Timestamp("2001-01-01"));
138+
value = annotated;
139+
assert(value == annotated);
140+
value = annotated.IonAlgebraic;
141+
assert(value == annotated);
142+
}

source/mir/algorithm/iteration.d

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4119,37 +4119,29 @@ template rcfilter(alias pred = "a", alias map = "a")
41194119
auto rcfilter(Range)(Range r)
41204120
if (isIterable!Range && (!isSlice!Range || DimensionCount!Range == 1))
41214121
{
4122-
import core.lifetime: forward;
4123-
import mir.primitives: isInputRange;
4124-
import mir.rc.array: RCArray;
4125-
4126-
if (false)
4122+
import core.lifetime: forward;
4123+
import mir.appender: scopedBuffer;
4124+
import mir.primitives: isInputRange;
4125+
import mir.rc.array: RCArray;
4126+
4127+
alias T = typeof(map(r.front));
4128+
auto buffer = scopedBuffer!T;
4129+
foreach (ref e; r)
4130+
{
4131+
if (pred(e))
41274132
{
4128-
auto p = pred(r.front);
4129-
auto e = map(r.front);
4130-
r.popFront;
4131-
auto d = r.empty;
4133+
static if (__traits(isSame, naryFun!"a", map))
4134+
buffer.put(forward!e);
4135+
else
4136+
buffer.put(map(forward!e));
41324137
}
4133-
return () @trusted
4134-
{
4135-
import mir.appender: ScopedBuffer;
4136-
alias T = typeof(map(r.front));
4137-
ScopedBuffer!T buffer = void;
4138-
buffer.initialize;
4139-
foreach (ref e; r)
4140-
{
4141-
if (pred(e))
4142-
{
4143-
static if (__traits(isSame, naryFun!"a", map))
4144-
buffer.put(forward!e);
4145-
else
4146-
buffer.put(map(forward!e));
4147-
}
4148-
}
4149-
auto ret = RCArray!T(buffer.length);
4150-
buffer.moveDataAndEmplaceTo(ret[]);
4151-
return ret;
4152-
} ();
4138+
}
4139+
return () @trusted
4140+
{
4141+
auto ret = RCArray!T(buffer.length);
4142+
buffer.moveDataAndEmplaceTo(ret[]);
4143+
return ret;
4144+
} ();
41534145
}
41544146

41554147
/// ditto

0 commit comments

Comments
 (0)