mt-lang 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/index.html +4 -3
- data/lib/milk_tea/base.rb +1 -1
- data/std/asset_pack.mt +267 -0
- data/std/async/libuv_runtime.mt +539 -0
- data/std/async/mailbox.mt +191 -0
- data/std/async/runtime.mt +87 -0
- data/std/async.mt +87 -0
- data/std/base64.mt +185 -0
- data/std/behavior_tree.mt +396 -0
- data/std/binary.mt +314 -0
- data/std/binary_heap.mt +157 -0
- data/std/bitset.mt +239 -0
- data/std/box2d.mt +535 -0
- data/std/bytes.mt +46 -0
- data/std/c/box2d.mt +1254 -0
- data/std/c/cgltf.mt +647 -0
- data/std/c/cjson.mt +106 -0
- data/std/c/crypto.mt +11 -0
- data/std/c/crypto_support.h +51 -0
- data/std/c/ctype.mt +19 -0
- data/std/c/ctype_bindgen.h +29 -0
- data/std/c/curl.mt +1223 -0
- data/std/c/enet.mt +473 -0
- data/std/c/errno.mt +41 -0
- data/std/c/errno_bindgen.h +53 -0
- data/std/c/flecs.mt +2945 -0
- data/std/c/fs.linux.mt +43 -0
- data/std/c/fs.windows.mt +43 -0
- data/std/c/fs_support.h +954 -0
- data/std/c/gl.mt +2065 -0
- data/std/c/gl_registry_helpers.h +10748 -0
- data/std/c/glfw.mt +499 -0
- data/std/c/libc.mt +167 -0
- data/std/c/libuv.mt +1491 -0
- data/std/c/math.mt +22 -0
- data/std/c/math_bindgen.h +31 -0
- data/std/c/miniaudio.mt +3420 -0
- data/std/c/pcre2.mt +735 -0
- data/std/c/process.mt +58 -0
- data/std/c/process_support.h +1147 -0
- data/std/c/raygui.mt +1602 -0
- data/std/c/raylib.mt +1245 -0
- data/std/c/raymath.mt +163 -0
- data/std/c/rlgl.mt +434 -0
- data/std/c/rpng.mt +60 -0
- data/std/c/rres.mt +187 -0
- data/std/c/sdl3.mt +4132 -0
- data/std/c/sqlite3.mt +951 -0
- data/std/c/stb_image.mt +52 -0
- data/std/c/stb_image_resize2.mt +128 -0
- data/std/c/stb_image_write.mt +19 -0
- data/std/c/stb_rect_pack.mt +38 -0
- data/std/c/stb_truetype.mt +175 -0
- data/std/c/stb_vorbis.mt +31 -0
- data/std/c/stdio.mt +90 -0
- data/std/c/steamworks.h +5769 -0
- data/std/c/steamworks.mt +4771 -0
- data/std/c/string.mt +16 -0
- data/std/c/string_bindgen.h +36 -0
- data/std/c/sync.mt +33 -0
- data/std/c/sync_support.h +219 -0
- data/std/c/terminal.mt +24 -0
- data/std/c/terminal_support.h +408 -0
- data/std/c/time.mt +26 -0
- data/std/c/tls.mt +24 -0
- data/std/c/tls_support.h +626 -0
- data/std/c/tracy.mt +53 -0
- data/std/c/zlib.mt +20 -0
- data/std/c/zlib_support.h +239 -0
- data/std/c/zstd.mt +231 -0
- data/std/cell.mt +60 -0
- data/std/cgltf.mt +115 -0
- data/std/cjson.mt +90 -0
- data/std/cli.mt +768 -0
- data/std/cookie.mt +198 -0
- data/std/counter.mt +160 -0
- data/std/crypto.mt +74 -0
- data/std/cstring.mt +13 -0
- data/std/ctype.mt +52 -0
- data/std/curl/runtime.mt +261 -0
- data/std/curl.mt +38 -0
- data/std/deque.mt +348 -0
- data/std/encoding.mt +93 -0
- data/std/enet.mt +133 -0
- data/std/env.mt +41 -0
- data/std/errno.mt +47 -0
- data/std/flecs.mt +978 -0
- data/std/fmt.mt +271 -0
- data/std/fs.linux.mt +696 -0
- data/std/fs.windows.mt +711 -0
- data/std/fsm.mt +267 -0
- data/std/gl.mt +2062 -0
- data/std/glfw.mt +471 -0
- data/std/goap.mt +342 -0
- data/std/graph.mt +521 -0
- data/std/gzip.mt +77 -0
- data/std/hash.mt +429 -0
- data/std/http/server.mt +810 -0
- data/std/http.mt +1227 -0
- data/std/intern.mt +53 -0
- data/std/jobs.mt +288 -0
- data/std/json.mt +627 -0
- data/std/libc.mt +34 -0
- data/std/libuv.mt +554 -0
- data/std/linear_algebra.mt +243 -0
- data/std/linked_map.mt +372 -0
- data/std/linked_map_view.mt +49 -0
- data/std/linked_set.mt +117 -0
- data/std/log.mt +69 -0
- data/std/map.mt +418 -0
- data/std/math.mt +24 -0
- data/std/mem/arena.mt +137 -0
- data/std/mem/endian.mt +51 -0
- data/std/mem/heap.mt +298 -0
- data/std/mem/pool.mt +164 -0
- data/std/mem/stack.mt +47 -0
- data/std/mem/tracking.mt +119 -0
- data/std/miniaudio.mt +1299 -0
- data/std/multiset.mt +191 -0
- data/std/net/channel.mt +727 -0
- data/std/net/clock.mt +237 -0
- data/std/net/discovery.mt +277 -0
- data/std/net/lobby.mt +813 -0
- data/std/net/manager.mt +539 -0
- data/std/net/mux.mt +839 -0
- data/std/net/nat.mt +122 -0
- data/std/net/packet.mt +219 -0
- data/std/net/punch.mt +162 -0
- data/std/net/rpc.mt +119 -0
- data/std/net/session.mt +1157 -0
- data/std/net/stun.mt +252 -0
- data/std/net/sync.mt +183 -0
- data/std/net/turn.mt +459 -0
- data/std/net.mt +2944 -0
- data/std/oauth2.mt +408 -0
- data/std/option.mt +51 -0
- data/std/ordered_map.mt +497 -0
- data/std/ordered_set.mt +348 -0
- data/std/path.mt +368 -0
- data/std/pcre2/runtime.mt +35 -0
- data/std/pcre2.mt +78 -0
- data/std/priority_queue.mt +55 -0
- data/std/process.mt +837 -0
- data/std/queue.mt +55 -0
- data/std/random.mt +146 -0
- data/std/raygui.mt +99 -0
- data/std/raylib/debug_console.mt +71 -0
- data/std/raylib/easing.mt +388 -0
- data/std/raylib/packed_assets.mt +255 -0
- data/std/raylib/runtime.mt +30 -0
- data/std/raylib/tracy_gpu.mt +37 -0
- data/std/raylib.mt +1510 -0
- data/std/raymath.mt +153 -0
- data/std/result.mt +89 -0
- data/std/rlgl.mt +268 -0
- data/std/rpng.mt +46 -0
- data/std/rres.mt +36 -0
- data/std/sdl3/runtime.mt +54 -0
- data/std/sdl3.mt +1731 -0
- data/std/serialize.mt +68 -0
- data/std/set.mt +124 -0
- data/std/spatial.mt +176 -0
- data/std/sqlite3.mt +151 -0
- data/std/stack.mt +55 -0
- data/std/stb_image.mt +47 -0
- data/std/stb_image_resize2.mt +41 -0
- data/std/stb_image_write.mt +17 -0
- data/std/stb_rect_pack.mt +15 -0
- data/std/stb_truetype.mt +77 -0
- data/std/stb_vorbis.mt +16 -0
- data/std/stdio.mt +88 -0
- data/std/steamworks.mt +1542 -0
- data/std/str.mt +293 -0
- data/std/string.mt +234 -0
- data/std/sync.mt +194 -0
- data/std/tar.mt +704 -0
- data/std/terminal.mt +1002 -0
- data/std/testing.mt +266 -0
- data/std/thread.mt +120 -0
- data/std/time.mt +105 -0
- data/std/tls.mt +616 -0
- data/std/toml.mt +1310 -0
- data/std/tracy.mt +42 -0
- data/std/uri.mt +118 -0
- data/std/url.mt +372 -0
- data/std/vec.mt +433 -0
- data/std/zstd.mt +94 -0
- metadata +187 -2
data/std/vec.mt
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import std.mem.heap as heap
|
|
2
|
+
|
|
3
|
+
public struct Vec[T]:
|
|
4
|
+
data: own[T]?
|
|
5
|
+
len: ptr_uint
|
|
6
|
+
capacity: ptr_uint
|
|
7
|
+
|
|
8
|
+
public struct Iter[T]:
|
|
9
|
+
data: ptr[T]?
|
|
10
|
+
index: ptr_uint
|
|
11
|
+
len: ptr_uint
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
extending Vec[T]:
|
|
15
|
+
public static function create() -> Vec[T]:
|
|
16
|
+
return Vec[T](data = null, len = 0, capacity = 0)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
public static function with_capacity(capacity: ptr_uint) -> Vec[T]:
|
|
20
|
+
var result = Vec[T].create()
|
|
21
|
+
result.reserve(capacity)
|
|
22
|
+
return result
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
public function len() -> ptr_uint:
|
|
26
|
+
return this.len
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
public function capacity() -> ptr_uint:
|
|
30
|
+
return this.capacity
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
public function is_empty() -> bool:
|
|
34
|
+
return this.len == 0
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
public function iter() -> Iter[T]:
|
|
38
|
+
return Iter[T](data = this.data, index = 0, len = this.len)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
public function as_span() -> span[T]:
|
|
42
|
+
if this.data == null and this.len != 0:
|
|
43
|
+
fatal(c"vec.Vec.as_span missing storage")
|
|
44
|
+
|
|
45
|
+
unsafe:
|
|
46
|
+
return span[T](data = ptr[T]<-this.data, len = this.len)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
public function get(index: ptr_uint) -> ptr[T]?:
|
|
50
|
+
if index >= this.len:
|
|
51
|
+
return null
|
|
52
|
+
|
|
53
|
+
let data = this.data else:
|
|
54
|
+
fatal(c"vec.Vec.get missing storage")
|
|
55
|
+
|
|
56
|
+
return unsafe: ptr[T]<-data + index
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
public function at(index: ptr_uint) -> Option[T]:
|
|
60
|
+
let p = this.get(index) else:
|
|
61
|
+
return Option[T].none
|
|
62
|
+
|
|
63
|
+
unsafe:
|
|
64
|
+
return Option[T].some(value = read(p))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
public function first() -> ptr[T]?:
|
|
68
|
+
return this.get(0)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
public function last() -> ptr[T]?:
|
|
72
|
+
if this.len == 0:
|
|
73
|
+
return null
|
|
74
|
+
|
|
75
|
+
return this.get(this.len - 1)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
public function find(predicate: proc(value: ptr[T]) -> bool) -> ptr[T]?:
|
|
79
|
+
var iter = this.iter()
|
|
80
|
+
return iter.find(predicate)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
public function find_index(predicate: proc(value: ptr[T]) -> bool) -> Option[ptr_uint]:
|
|
84
|
+
var iter = this.iter()
|
|
85
|
+
return iter.position(predicate)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
public editable function clear() -> void:
|
|
89
|
+
this.len = 0
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
public editable function release() -> void:
|
|
93
|
+
heap.release(this.data)
|
|
94
|
+
this.data = null
|
|
95
|
+
this.len = 0
|
|
96
|
+
this.capacity = 0
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
public editable function reserve(min_capacity: ptr_uint) -> void:
|
|
100
|
+
if min_capacity <= this.capacity:
|
|
101
|
+
return
|
|
102
|
+
|
|
103
|
+
var new_capacity = this.capacity
|
|
104
|
+
if new_capacity == 0:
|
|
105
|
+
new_capacity = 4
|
|
106
|
+
|
|
107
|
+
while new_capacity < min_capacity:
|
|
108
|
+
if new_capacity > heap.ptr_uint_max / 2:
|
|
109
|
+
new_capacity = min_capacity
|
|
110
|
+
else:
|
|
111
|
+
new_capacity *= 2
|
|
112
|
+
|
|
113
|
+
let resized = heap.resize[T](this.data, new_capacity) else:
|
|
114
|
+
fatal(c"vec.reserve out of memory")
|
|
115
|
+
|
|
116
|
+
this.data = resized
|
|
117
|
+
this.capacity = new_capacity
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
public editable function append_span(values: span[T]) -> void:
|
|
121
|
+
if values.len == 0:
|
|
122
|
+
return
|
|
123
|
+
|
|
124
|
+
let current_len = this.len
|
|
125
|
+
if values.len > heap.ptr_uint_max - current_len:
|
|
126
|
+
fatal(c"vec.append_span size overflow")
|
|
127
|
+
|
|
128
|
+
let new_len = current_len + values.len
|
|
129
|
+
let needs_growth = new_len > this.capacity
|
|
130
|
+
|
|
131
|
+
var copied: ptr[T]? = null
|
|
132
|
+
if needs_growth:
|
|
133
|
+
copied = heap.must_alloc[T](values.len)
|
|
134
|
+
unsafe:
|
|
135
|
+
let copied_ptr = ptr[T]<-copied
|
|
136
|
+
var index: ptr_uint = 0
|
|
137
|
+
while index < values.len:
|
|
138
|
+
read(copied_ptr + index) = read(values.data + index)
|
|
139
|
+
index += 1
|
|
140
|
+
|
|
141
|
+
this.reserve(new_len)
|
|
142
|
+
|
|
143
|
+
let data = this.data else:
|
|
144
|
+
fatal(c"vec.append_span missing storage")
|
|
145
|
+
|
|
146
|
+
unsafe:
|
|
147
|
+
let destination = ptr[T]<-data + current_len
|
|
148
|
+
if copied != null:
|
|
149
|
+
let copied_ptr = ptr[T]<-copied
|
|
150
|
+
var index: ptr_uint = 0
|
|
151
|
+
while index < values.len:
|
|
152
|
+
read(destination + index) = read(copied_ptr + index)
|
|
153
|
+
index += 1
|
|
154
|
+
heap.release(copied)
|
|
155
|
+
else:
|
|
156
|
+
var index: ptr_uint = 0
|
|
157
|
+
while index < values.len:
|
|
158
|
+
read(destination + index) = read(values.data + index)
|
|
159
|
+
index += 1
|
|
160
|
+
|
|
161
|
+
this.len = new_len
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
public editable function append_array[N](values: array[T, N]) -> void:
|
|
165
|
+
var local_values = values
|
|
166
|
+
this.append_span(local_values)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
public editable function insert(index: ptr_uint, value: T) -> bool:
|
|
170
|
+
if index > this.len:
|
|
171
|
+
return false
|
|
172
|
+
|
|
173
|
+
if this.len == this.capacity:
|
|
174
|
+
this.reserve(this.len + 1)
|
|
175
|
+
|
|
176
|
+
let data = this.data else:
|
|
177
|
+
fatal(c"vec.insert missing storage")
|
|
178
|
+
|
|
179
|
+
unsafe:
|
|
180
|
+
let data_ptr = ptr[T]<-data
|
|
181
|
+
var current = this.len
|
|
182
|
+
while current > index:
|
|
183
|
+
let previous = current - 1
|
|
184
|
+
read(data_ptr + current) = read(data_ptr + previous)
|
|
185
|
+
current = previous
|
|
186
|
+
read(data_ptr + index) = value
|
|
187
|
+
|
|
188
|
+
this.len += 1
|
|
189
|
+
return true
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
public editable function push(value: T) -> void:
|
|
193
|
+
if this.len == this.capacity:
|
|
194
|
+
this.reserve(this.len + 1)
|
|
195
|
+
|
|
196
|
+
let data = this.data else:
|
|
197
|
+
fatal(c"vec.push missing storage")
|
|
198
|
+
|
|
199
|
+
unsafe:
|
|
200
|
+
let data_ptr = ptr[T]<-data
|
|
201
|
+
read(data_ptr + this.len) = value
|
|
202
|
+
|
|
203
|
+
this.len += 1
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
public editable function pop() -> Option[T]:
|
|
207
|
+
if this.len == 0:
|
|
208
|
+
return Option[T].none
|
|
209
|
+
|
|
210
|
+
let data = this.data else:
|
|
211
|
+
fatal(c"vec.pop missing storage")
|
|
212
|
+
|
|
213
|
+
let last_index = this.len - 1
|
|
214
|
+
unsafe:
|
|
215
|
+
let data_ptr = ptr[T]<-data
|
|
216
|
+
let value = read(data_ptr + last_index)
|
|
217
|
+
this.len = last_index
|
|
218
|
+
return Option[T].some(value = value)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
public editable function remove(index: ptr_uint) -> Option[T]:
|
|
222
|
+
if index >= this.len:
|
|
223
|
+
return Option[T].none
|
|
224
|
+
|
|
225
|
+
let data = this.data else:
|
|
226
|
+
fatal(c"vec.remove missing storage")
|
|
227
|
+
|
|
228
|
+
let last_index = this.len - 1
|
|
229
|
+
unsafe:
|
|
230
|
+
let data_ptr = ptr[T]<-data
|
|
231
|
+
let removed = read(data_ptr + index)
|
|
232
|
+
var current = index
|
|
233
|
+
while current < last_index:
|
|
234
|
+
let next_index = current + 1
|
|
235
|
+
read(data_ptr + current) = read(data_ptr + next_index)
|
|
236
|
+
current = next_index
|
|
237
|
+
this.len = last_index
|
|
238
|
+
return Option[T].some(value = removed)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
public editable function swap_remove(index: ptr_uint) -> Option[T]:
|
|
242
|
+
if index >= this.len:
|
|
243
|
+
return Option[T].none
|
|
244
|
+
|
|
245
|
+
let data = this.data else:
|
|
246
|
+
fatal(c"vec.swap_remove missing storage")
|
|
247
|
+
|
|
248
|
+
let last_index = this.len - 1
|
|
249
|
+
unsafe:
|
|
250
|
+
let data_ptr = ptr[T]<-data
|
|
251
|
+
let removed = read(data_ptr + index)
|
|
252
|
+
if index != last_index:
|
|
253
|
+
read(data_ptr + index) = read(data_ptr + last_index)
|
|
254
|
+
this.len = last_index
|
|
255
|
+
return Option[T].some(value = removed)
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
public editable function swap(i: ptr_uint, j: ptr_uint) -> void:
|
|
259
|
+
if i >= this.len or j >= this.len:
|
|
260
|
+
return
|
|
261
|
+
|
|
262
|
+
let data = this.data else:
|
|
263
|
+
fatal(c"vec.swap missing storage")
|
|
264
|
+
|
|
265
|
+
if i == j:
|
|
266
|
+
return
|
|
267
|
+
|
|
268
|
+
unsafe:
|
|
269
|
+
let data_ptr = ptr[T]<-data
|
|
270
|
+
var temp = read(data_ptr + i)
|
|
271
|
+
read(data_ptr + i) = read(data_ptr + j)
|
|
272
|
+
read(data_ptr + j) = temp
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
extending Iter[T]:
|
|
276
|
+
public function iter() -> Iter[T]:
|
|
277
|
+
return this
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
public editable function next() -> ptr[T]?:
|
|
281
|
+
if this.index >= this.len:
|
|
282
|
+
return null
|
|
283
|
+
|
|
284
|
+
let data = this.data else:
|
|
285
|
+
fatal(c"vec.Iter.next missing storage")
|
|
286
|
+
|
|
287
|
+
let current_index = this.index
|
|
288
|
+
this.index += 1
|
|
289
|
+
return unsafe: ptr[T]<-data + current_index
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
public editable function find(predicate: proc(value: ptr[T]) -> bool) -> ptr[T]?:
|
|
293
|
+
while true:
|
|
294
|
+
let current = this.next() else:
|
|
295
|
+
return null
|
|
296
|
+
|
|
297
|
+
if predicate(current):
|
|
298
|
+
return current
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
public editable function position(predicate: proc(value: ptr[T]) -> bool) -> Option[ptr_uint]:
|
|
302
|
+
while true:
|
|
303
|
+
let current_index = this.index
|
|
304
|
+
let current = this.next() else:
|
|
305
|
+
return Option[ptr_uint].none
|
|
306
|
+
|
|
307
|
+
if predicate(current):
|
|
308
|
+
return Option[ptr_uint].some(value = current_index)
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
public editable function any(predicate: proc(value: ptr[T]) -> bool) -> bool:
|
|
312
|
+
return this.find(predicate) != null
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
public editable function all(predicate: proc(value: ptr[T]) -> bool) -> bool:
|
|
316
|
+
while true:
|
|
317
|
+
let current = this.next() else:
|
|
318
|
+
return true
|
|
319
|
+
|
|
320
|
+
if not predicate(current):
|
|
321
|
+
return false
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
public editable function count(predicate: proc(value: ptr[T]) -> bool) -> ptr_uint:
|
|
325
|
+
var total: ptr_uint = 0
|
|
326
|
+
while true:
|
|
327
|
+
let current = this.next() else:
|
|
328
|
+
return total
|
|
329
|
+
|
|
330
|
+
if predicate(current):
|
|
331
|
+
total += 1
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
public editable function sort() -> void:
|
|
335
|
+
if this.len <= 1:
|
|
336
|
+
return
|
|
337
|
+
|
|
338
|
+
let data = this.data else:
|
|
339
|
+
fatal(c"vec.sort missing storage")
|
|
340
|
+
|
|
341
|
+
unsafe:
|
|
342
|
+
let data_ptr = ptr[T]<-data
|
|
343
|
+
var gap = this.len
|
|
344
|
+
while true:
|
|
345
|
+
gap = gap * 10 / 13
|
|
346
|
+
if gap < 1:
|
|
347
|
+
gap = 1
|
|
348
|
+
|
|
349
|
+
var i = gap
|
|
350
|
+
while i < this.len:
|
|
351
|
+
var j = i
|
|
352
|
+
let temp = read(data_ptr + j)
|
|
353
|
+
while j >= gap and order[T](data_ptr + j - gap, temp) > 0:
|
|
354
|
+
read(data_ptr + j) = read(data_ptr + j - gap)
|
|
355
|
+
j -= gap
|
|
356
|
+
|
|
357
|
+
read(data_ptr + j) = temp
|
|
358
|
+
i += 1
|
|
359
|
+
|
|
360
|
+
if gap == 1:
|
|
361
|
+
break
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
public editable function sort_by(comparator: proc(left: ptr[T], right: ptr[T]) -> int) -> void:
|
|
365
|
+
if this.len <= 1:
|
|
366
|
+
return
|
|
367
|
+
|
|
368
|
+
let data = this.data else:
|
|
369
|
+
fatal(c"vec.sort_by missing storage")
|
|
370
|
+
|
|
371
|
+
unsafe:
|
|
372
|
+
let data_ptr = ptr[T]<-data
|
|
373
|
+
var gap = this.len
|
|
374
|
+
while true:
|
|
375
|
+
gap = gap * 10 / 13
|
|
376
|
+
if gap < 1:
|
|
377
|
+
gap = 1
|
|
378
|
+
|
|
379
|
+
var i = gap
|
|
380
|
+
while i < this.len:
|
|
381
|
+
var j = i
|
|
382
|
+
var temp = read(data_ptr + j)
|
|
383
|
+
while j >= gap and comparator(data_ptr + j - gap, ptr_of(temp)) > 0:
|
|
384
|
+
read(data_ptr + j) = read(data_ptr + j - gap)
|
|
385
|
+
j -= gap
|
|
386
|
+
|
|
387
|
+
read(data_ptr + j) = temp
|
|
388
|
+
i += 1
|
|
389
|
+
|
|
390
|
+
if gap == 1:
|
|
391
|
+
break
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
public function binary_search(target: ptr[T]) -> Option[ptr_uint]:
|
|
395
|
+
let data = this.data else:
|
|
396
|
+
fatal(c"vec.binary_search missing storage")
|
|
397
|
+
|
|
398
|
+
unsafe:
|
|
399
|
+
let data_ptr = ptr[T]<-data
|
|
400
|
+
var low: ptr_uint = 0
|
|
401
|
+
var high = this.len
|
|
402
|
+
while low < high:
|
|
403
|
+
let mid = low + (high - low) / 2
|
|
404
|
+
let cmp = order[T](target, data_ptr + mid)
|
|
405
|
+
if cmp < 0:
|
|
406
|
+
high = mid
|
|
407
|
+
else if cmp > 0:
|
|
408
|
+
low = mid + 1
|
|
409
|
+
else:
|
|
410
|
+
return Option[ptr_uint].some(value = mid)
|
|
411
|
+
|
|
412
|
+
return Option[ptr_uint].none
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
public function binary_search_by(target: ptr[T], comparator: proc(target: ptr[T], element: ptr[T]) -> int) -> Option[ptr_uint]:
|
|
416
|
+
let data = this.data else:
|
|
417
|
+
fatal(c"vec.binary_search_by missing storage")
|
|
418
|
+
|
|
419
|
+
unsafe:
|
|
420
|
+
let data_ptr = ptr[T]<-data
|
|
421
|
+
var low: ptr_uint = 0
|
|
422
|
+
var high = this.len
|
|
423
|
+
while low < high:
|
|
424
|
+
let mid = low + (high - low) / 2
|
|
425
|
+
let cmp = comparator(target, data_ptr + mid)
|
|
426
|
+
if cmp < 0:
|
|
427
|
+
high = mid
|
|
428
|
+
else if cmp > 0:
|
|
429
|
+
low = mid + 1
|
|
430
|
+
else:
|
|
431
|
+
return Option[ptr_uint].some(value = mid)
|
|
432
|
+
|
|
433
|
+
return Option[ptr_uint].none
|
data/std/zstd.mt
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# generated by mtc imported-bindings from std.c.zstd using bindings/imported/zstd.binding.json
|
|
2
|
+
|
|
3
|
+
import std.c.zstd as c
|
|
4
|
+
|
|
5
|
+
public type ZSTD_ErrorCode = c.ZSTD_ErrorCode
|
|
6
|
+
public type ZSTD_CCtx = c.ZSTD_CCtx
|
|
7
|
+
public type ZSTD_DCtx = c.ZSTD_DCtx
|
|
8
|
+
public type ZSTD_strategy = c.ZSTD_strategy
|
|
9
|
+
public type ZSTD_cParameter = c.ZSTD_cParameter
|
|
10
|
+
public type ZSTD_bounds = c.ZSTD_bounds
|
|
11
|
+
public type ZSTD_ResetDirective = c.ZSTD_ResetDirective
|
|
12
|
+
public type ZSTD_dParameter = c.ZSTD_dParameter
|
|
13
|
+
public type ZSTD_inBuffer = c.ZSTD_inBuffer
|
|
14
|
+
public type ZSTD_outBuffer = c.ZSTD_outBuffer
|
|
15
|
+
public type ZSTD_CStream = c.ZSTD_CStream
|
|
16
|
+
public type ZSTD_EndDirective = c.ZSTD_EndDirective
|
|
17
|
+
public type ZSTD_DStream = c.ZSTD_DStream
|
|
18
|
+
public type ZSTD_CDict = c.ZSTD_CDict
|
|
19
|
+
public type ZSTD_DDict = c.ZSTD_DDict
|
|
20
|
+
|
|
21
|
+
public const ZSTD_VERSION_MAJOR: int = c.ZSTD_VERSION_MAJOR
|
|
22
|
+
public const ZSTD_VERSION_MINOR: int = c.ZSTD_VERSION_MINOR
|
|
23
|
+
public const ZSTD_VERSION_RELEASE: int = c.ZSTD_VERSION_RELEASE
|
|
24
|
+
public const ZSTD_CLEVEL_DEFAULT: int = c.ZSTD_CLEVEL_DEFAULT
|
|
25
|
+
public const ZSTD_MAGICNUMBER: uint = c.ZSTD_MAGICNUMBER
|
|
26
|
+
public const ZSTD_MAGIC_DICTIONARY: uint = c.ZSTD_MAGIC_DICTIONARY
|
|
27
|
+
public const ZSTD_MAGIC_SKIPPABLE_START: int = c.ZSTD_MAGIC_SKIPPABLE_START
|
|
28
|
+
public const ZSTD_MAGIC_SKIPPABLE_MASK: uint = c.ZSTD_MAGIC_SKIPPABLE_MASK
|
|
29
|
+
public const ZSTD_BLOCKSIZELOG_MAX: int = c.ZSTD_BLOCKSIZELOG_MAX
|
|
30
|
+
|
|
31
|
+
public foreign function version_number() -> uint = c.ZSTD_versionNumber
|
|
32
|
+
public foreign function version_string() -> cstr = c.ZSTD_versionString
|
|
33
|
+
public foreign function compress(dst: ptr[void], dst_capacity: ptr_uint, src: const_ptr[void], src_size: ptr_uint, compression_level: int) -> ptr_uint = c.ZSTD_compress
|
|
34
|
+
public foreign function decompress(dst: ptr[void], dst_capacity: ptr_uint, src: const_ptr[void], compressed_size: ptr_uint) -> ptr_uint = c.ZSTD_decompress
|
|
35
|
+
public foreign function get_frame_content_size(src: const_ptr[void], src_size: ptr_uint) -> ulong = c.ZSTD_getFrameContentSize
|
|
36
|
+
public foreign function get_decompressed_size(src: const_ptr[void], src_size: ptr_uint) -> ulong = c.ZSTD_getDecompressedSize
|
|
37
|
+
public foreign function find_frame_compressed_size(src: const_ptr[void], src_size: ptr_uint) -> ptr_uint = c.ZSTD_findFrameCompressedSize
|
|
38
|
+
public foreign function compress_bound(src_size: ptr_uint) -> ptr_uint = c.ZSTD_compressBound
|
|
39
|
+
public foreign function is_error(result: ptr_uint) -> uint = c.ZSTD_isError
|
|
40
|
+
public foreign function get_error_name(result: ptr_uint) -> cstr = c.ZSTD_getErrorName
|
|
41
|
+
public foreign function min_c_level() -> int = c.ZSTD_minCLevel
|
|
42
|
+
public foreign function max_c_level() -> int = c.ZSTD_maxCLevel
|
|
43
|
+
public foreign function default_c_level() -> int = c.ZSTD_defaultCLevel
|
|
44
|
+
public foreign function create_c_ctx() -> ptr[ZSTD_CCtx] = c.ZSTD_createCCtx
|
|
45
|
+
public foreign function free_c_ctx(cctx: ptr[ZSTD_CCtx]) -> ptr_uint = c.ZSTD_freeCCtx
|
|
46
|
+
public foreign function compress_c_ctx(cctx: ptr[ZSTD_CCtx], dst: ptr[void], dst_capacity: ptr_uint, src: const_ptr[void], src_size: ptr_uint, compression_level: int) -> ptr_uint = c.ZSTD_compressCCtx
|
|
47
|
+
public foreign function create_d_ctx() -> ptr[ZSTD_DCtx] = c.ZSTD_createDCtx
|
|
48
|
+
public foreign function free_d_ctx(dctx: ptr[ZSTD_DCtx]) -> ptr_uint = c.ZSTD_freeDCtx
|
|
49
|
+
public foreign function decompress_d_ctx(dctx: ptr[ZSTD_DCtx], dst: ptr[void], dst_capacity: ptr_uint, src: const_ptr[void], src_size: ptr_uint) -> ptr_uint = c.ZSTD_decompressDCtx
|
|
50
|
+
public foreign function c_ctx_set_parameter(cctx: ptr[ZSTD_CCtx], param: ZSTD_cParameter, value: int) -> ptr_uint = c.ZSTD_CCtx_setParameter
|
|
51
|
+
public foreign function c_ctx_set_pledged_src_size(cctx: ptr[ZSTD_CCtx], pledged_src_size: ulong) -> ptr_uint = c.ZSTD_CCtx_setPledgedSrcSize
|
|
52
|
+
public foreign function c_ctx_reset(cctx: ptr[ZSTD_CCtx], reset: ZSTD_ResetDirective) -> ptr_uint = c.ZSTD_CCtx_reset
|
|
53
|
+
public foreign function compress2(cctx: ptr[ZSTD_CCtx], dst: ptr[void], dst_capacity: ptr_uint, src: const_ptr[void], src_size: ptr_uint) -> ptr_uint = c.ZSTD_compress2
|
|
54
|
+
public foreign function d_ctx_set_parameter(dctx: ptr[ZSTD_DCtx], param: ZSTD_dParameter, value: int) -> ptr_uint = c.ZSTD_DCtx_setParameter
|
|
55
|
+
public foreign function d_ctx_reset(dctx: ptr[ZSTD_DCtx], reset: ZSTD_ResetDirective) -> ptr_uint = c.ZSTD_DCtx_reset
|
|
56
|
+
public foreign function create_c_stream() -> ptr[ZSTD_CStream] = c.ZSTD_createCStream
|
|
57
|
+
public foreign function free_c_stream(zcs: ptr[ZSTD_CStream]) -> ptr_uint = c.ZSTD_freeCStream
|
|
58
|
+
public foreign function compress_stream2(cctx: ptr[ZSTD_CCtx], output: ptr[ZSTD_outBuffer], input: ptr[ZSTD_inBuffer], end_op: ZSTD_EndDirective) -> ptr_uint = c.ZSTD_compressStream2
|
|
59
|
+
public foreign function c_stream_in_size() -> ptr_uint = c.ZSTD_CStreamInSize
|
|
60
|
+
public foreign function c_stream_out_size() -> ptr_uint = c.ZSTD_CStreamOutSize
|
|
61
|
+
public foreign function init_c_stream(zcs: ptr[ZSTD_CStream], compression_level: int) -> ptr_uint = c.ZSTD_initCStream
|
|
62
|
+
public foreign function compress_stream(zcs: ptr[ZSTD_CStream], output: ptr[ZSTD_outBuffer], input: ptr[ZSTD_inBuffer]) -> ptr_uint = c.ZSTD_compressStream
|
|
63
|
+
public foreign function flush_stream(zcs: ptr[ZSTD_CStream], output: ptr[ZSTD_outBuffer]) -> ptr_uint = c.ZSTD_flushStream
|
|
64
|
+
public foreign function end_stream(zcs: ptr[ZSTD_CStream], output: ptr[ZSTD_outBuffer]) -> ptr_uint = c.ZSTD_endStream
|
|
65
|
+
public foreign function create_d_stream() -> ptr[ZSTD_DStream] = c.ZSTD_createDStream
|
|
66
|
+
public foreign function free_d_stream(zds: ptr[ZSTD_DStream]) -> ptr_uint = c.ZSTD_freeDStream
|
|
67
|
+
public foreign function init_d_stream(zds: ptr[ZSTD_DStream]) -> ptr_uint = c.ZSTD_initDStream
|
|
68
|
+
public foreign function decompress_stream(zds: ptr[ZSTD_DStream], output: ptr[ZSTD_outBuffer], input: ptr[ZSTD_inBuffer]) -> ptr_uint = c.ZSTD_decompressStream
|
|
69
|
+
public foreign function d_stream_in_size() -> ptr_uint = c.ZSTD_DStreamInSize
|
|
70
|
+
public foreign function d_stream_out_size() -> ptr_uint = c.ZSTD_DStreamOutSize
|
|
71
|
+
public foreign function compress_using_dict(ctx: ptr[ZSTD_CCtx], dst: ptr[void], dst_capacity: ptr_uint, src: const_ptr[void], src_size: ptr_uint, dict: const_ptr[void], dict_size: ptr_uint, compression_level: int) -> ptr_uint = c.ZSTD_compress_usingDict
|
|
72
|
+
public foreign function decompress_using_dict(dctx: ptr[ZSTD_DCtx], dst: ptr[void], dst_capacity: ptr_uint, src: const_ptr[void], src_size: ptr_uint, dict: const_ptr[void], dict_size: ptr_uint) -> ptr_uint = c.ZSTD_decompress_usingDict
|
|
73
|
+
public foreign function create_c_dict(dict_buffer: const_ptr[void], dict_size: ptr_uint, compression_level: int) -> ptr[ZSTD_CDict] = c.ZSTD_createCDict
|
|
74
|
+
public foreign function free_c_dict(c_dict: ptr[ZSTD_CDict]) -> ptr_uint = c.ZSTD_freeCDict
|
|
75
|
+
public foreign function compress_using_c_dict(cctx: ptr[ZSTD_CCtx], dst: ptr[void], dst_capacity: ptr_uint, src: const_ptr[void], src_size: ptr_uint, cdict: const_ptr[ZSTD_CDict]) -> ptr_uint = c.ZSTD_compress_usingCDict
|
|
76
|
+
public foreign function create_d_dict(dict_buffer: const_ptr[void], dict_size: ptr_uint) -> ptr[ZSTD_DDict] = c.ZSTD_createDDict
|
|
77
|
+
public foreign function free_d_dict(ddict: ptr[ZSTD_DDict]) -> ptr_uint = c.ZSTD_freeDDict
|
|
78
|
+
public foreign function decompress_using_d_dict(dctx: ptr[ZSTD_DCtx], dst: ptr[void], dst_capacity: ptr_uint, src: const_ptr[void], src_size: ptr_uint, ddict: const_ptr[ZSTD_DDict]) -> ptr_uint = c.ZSTD_decompress_usingDDict
|
|
79
|
+
public foreign function get_dict_id_from_dict(dict: const_ptr[void], dict_size: ptr_uint) -> uint = c.ZSTD_getDictID_fromDict
|
|
80
|
+
public foreign function get_dict_id_from_c_dict(cdict: const_ptr[ZSTD_CDict]) -> uint = c.ZSTD_getDictID_fromCDict
|
|
81
|
+
public foreign function get_dict_id_from_d_dict(ddict: const_ptr[ZSTD_DDict]) -> uint = c.ZSTD_getDictID_fromDDict
|
|
82
|
+
public foreign function get_dict_id_from_frame(src: const_ptr[void], src_size: ptr_uint) -> uint = c.ZSTD_getDictID_fromFrame
|
|
83
|
+
public foreign function c_ctx_load_dictionary(cctx: ptr[ZSTD_CCtx], dict: const_ptr[void], dict_size: ptr_uint) -> ptr_uint = c.ZSTD_CCtx_loadDictionary
|
|
84
|
+
public foreign function c_ctx_ref_c_dict(cctx: ptr[ZSTD_CCtx], cdict: const_ptr[ZSTD_CDict]) -> ptr_uint = c.ZSTD_CCtx_refCDict
|
|
85
|
+
public foreign function c_ctx_ref_prefix(cctx: ptr[ZSTD_CCtx], prefix: const_ptr[void], prefix_size: ptr_uint) -> ptr_uint = c.ZSTD_CCtx_refPrefix
|
|
86
|
+
public foreign function d_ctx_load_dictionary(dctx: ptr[ZSTD_DCtx], dict: const_ptr[void], dict_size: ptr_uint) -> ptr_uint = c.ZSTD_DCtx_loadDictionary
|
|
87
|
+
public foreign function d_ctx_ref_d_dict(dctx: ptr[ZSTD_DCtx], ddict: const_ptr[ZSTD_DDict]) -> ptr_uint = c.ZSTD_DCtx_refDDict
|
|
88
|
+
public foreign function d_ctx_ref_prefix(dctx: ptr[ZSTD_DCtx], prefix: const_ptr[void], prefix_size: ptr_uint) -> ptr_uint = c.ZSTD_DCtx_refPrefix
|
|
89
|
+
public foreign function sizeof_c_ctx(cctx: const_ptr[ZSTD_CCtx]) -> ptr_uint = c.ZSTD_sizeof_CCtx
|
|
90
|
+
public foreign function sizeof_d_ctx(dctx: const_ptr[ZSTD_DCtx]) -> ptr_uint = c.ZSTD_sizeof_DCtx
|
|
91
|
+
public foreign function sizeof_c_stream(zcs: const_ptr[ZSTD_CStream]) -> ptr_uint = c.ZSTD_sizeof_CStream
|
|
92
|
+
public foreign function sizeof_d_stream(zds: const_ptr[ZSTD_DStream]) -> ptr_uint = c.ZSTD_sizeof_DStream
|
|
93
|
+
public foreign function sizeof_c_dict(cdict: const_ptr[ZSTD_CDict]) -> ptr_uint = c.ZSTD_sizeof_CDict
|
|
94
|
+
public foreign function sizeof_d_dict(ddict: const_ptr[ZSTD_DDict]) -> ptr_uint = c.ZSTD_sizeof_DDict
|