You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: daslib/algorithm.das
+19Lines changed: 19 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -77,10 +77,12 @@ def lower_bound(a : array<auto(TT)>; f, l : int; val : TT const -&) {
77
77
}
78
78
79
79
deflower_bound(a : array<auto(TT)>; val : TT const -&) {
80
+
//! Returns an iterator pointing to the first element in the array that is not less than (i.e. greater or equal to) value, or length(a) if no such element is found.
80
81
returnlower_bound(a, 0, length(a), val)
81
82
}
82
83
83
84
deflower_bound(a : array<auto(TT)>; f, l : int; value : auto(QQ); less : block<(a : TT const -&, b : QQ) : bool>) {
85
+
//! Returns an iterator pointing to the first element in the range [first, last) that is not less than (i.e. greater or equal to) value, or last if no such element is found.
84
86
assert(f>=0&&f<=l, "lower bound first out of range")
85
87
assert(l>=f&&l<=length(a), "lower bound last out of range")
86
88
varcount=l-f
@@ -99,10 +101,13 @@ def lower_bound(a : array<auto(TT)>; f, l : int; value : auto(QQ); less : block<
99
101
}
100
102
101
103
deflower_bound(a : array<auto(TT)>; value : auto(QQ); less : block<(a : TT const -&, b : QQ) : bool>) {
104
+
//! Returns an iterator pointing to the first element in the array that is not less than (i.e. greater or equal to) value, or length(a) if no such element is found.
102
105
returnlower_bound(a, 0, length(a), value, less)
103
106
}
104
107
105
108
defbinary_search(a : array<auto(TT)>; val : TT const -&) {
109
+
//! Returns true if an val appears within the array a.
110
+
//! Array a must be sorted.
106
111
letfirst=lower_bound(a, val)
107
112
return (first!=length(a)) && (!(val<a[first]))
108
113
}
@@ -115,12 +120,16 @@ def binary_search(a : array<auto(TT)>; f, last : int; val : TT const -&) {
115
120
}
116
121
117
122
defbinary_search(a : array<auto(TT)>; val : TT const -&; less : block<(a, b : TT const -&) : bool>) {
123
+
//! Returns true if an val appears within the array a.
124
+
//! Array a must be sorted according to the provided less function.
@@ -129,20 +138,23 @@ def binary_search(a : array<auto(TT)>; f, last : int; val : TT const -&; less :
129
138
130
139
[expect_any_array(a)]
131
140
defreverse(var a) {
141
+
//! Reverses the elements of array a in place.
132
142
unsafe {
133
143
reverse(temp_array(a))
134
144
}
135
145
}
136
146
137
147
[expect_any_array(a)]
138
148
defcombine(a, b) {
149
+
//! Returns array of the elements of a and then b.
139
150
unsafe {
140
151
returncombine(temp_array(a), temp_array(b))
141
152
}
142
153
}
143
154
144
155
[expect_any_array(a)]
145
156
deflower_bound(a; f, l : int; val) {
157
+
//! Returns an iterator pointing to the first element in the range [first, last) that is not less than (i.e. greater or equal to) value, or last if no such element is found.
concept_assert(false, "value type {typeinfostripped_typename(val)} should be the same as array {typeinfostripped_typename(a)} element type {typeinfostripped_typename(a[0])}")
//! Returns an iterator pointing to the first element in the array that is not less than (i.e. greater or equal to) value, or length(a) if no such element is found.
concept_assert(false, "value type {typeinfostripped_typename(val)} should be the same as array {typeinfostripped_typename(a)} element type {typeinfostripped_typename(a[0])}")
160
173
return-1
@@ -167,6 +180,7 @@ def lower_bound(a; val) {
167
180
168
181
[expect_any_array(a)]
169
182
deflower_bound(a; f, l : int; val : auto(TT); less : block<(a, b : TT const -&) : bool>) {
183
+
//! Returns an iterator pointing to the first element in the range [first, last) that is not less than (i.e. greater or equal to) value, or last if no such element is found.
concept_assert(false, "value type {typeinfostripped_typename(val)} should be the same as array {typeinfostripped_typename(a)} element type {typeinfostripped_typename(a[0])}")
172
186
return-1
@@ -179,6 +193,7 @@ def lower_bound(a; f, l : int; val : auto(TT); less : block<(a, b : TT const -&)
179
193
180
194
[expect_any_array(a)]
181
195
deflower_bound(a; val : auto(TT); less : block<(a, b : TT const -&) : bool>) {
196
+
//! Returns an iterator pointing to the first element in the array that is not less than (i.e. greater or equal to) value, or length(a) if no such element is found.
concept_assert(false, "value type {typeinfostripped_typename(val)} should be the same as array {typeinfostripped_typename(a)} element type {typeinfostripped_typename(a[0])}")
184
199
return-1
@@ -191,6 +206,7 @@ def lower_bound(a; val : auto(TT); less : block<(a, b : TT const -&) : bool>) {
191
206
192
207
[expect_any_array(a)]
193
208
defbinary_search(a; val) {
209
+
//! Returns true if an val appears within the array a.
concept_assert(false, "value type {typeinfostripped_typename(val)} should be the same as array {typeinfostripped_typename(a)} element type {typeinfostripped_typename(a[0])}")
196
212
return-1
@@ -203,6 +219,7 @@ def binary_search(a; val) {
203
219
204
220
[expect_any_array(a)]
205
221
defbinary_search(a; f, last : int; val) {
222
+
//! Returns true if an val appears within the range [f, last).
concept_assert(false, "value type {typeinfostripped_typename(val)} should be the same as array {typeinfostripped_typename(a)} element type {typeinfostripped_typename(a[0])}")
concept_assert(false, "value type {typeinfostripped_typename(val)} should be the same as array {typeinfostripped_typename(a)} element type {typeinfostripped_typename(a[0])}")
220
238
return-1
@@ -227,6 +245,7 @@ def binary_search(a; val : auto(TT); less : block<(a, b : TT const -&) : bool>)
227
245
228
246
[expect_any_array(a)]
229
247
defbinary_search(a; f, last : int; val : auto(TT); less : block<(a, b : TT const -&) : bool>) {
248
+
//! Returns true if an val appears within the range [f, last).
concept_assert(false, "value type {typeinfostripped_typename(val)} should be the same as array {typeinfostripped_typename(a)} element type {typeinfostripped_typename(a[0])}")
0 commit comments