Reduce memory consumtion. Add "range"

This commit is contained in:
Christoffer Lerno
2023-06-25 21:39:16 +02:00
parent 1dccd6af79
commit 8c73a450a1
8 changed files with 56 additions and 13 deletions

View File

@@ -0,0 +1,26 @@
/**
* @checked Type{} < Type{} : "The type must be comparable"
* @checked Type{} + (Type)1 : "The type must be possible to add to"
**/
module std::collections::range<Type>;
struct Range
{
Type start;
Type end;
}
fn usz Range.len(Range* range) @operator(len)
{
if (range.end < range.start) return 0;
return (usz)(range.end - range.start);
}
/**
* @require index < range.len() : "Can't index into an empty range"
**/
fn Type Range.get(Range* range, usz index) @operator([])
{
return range.start + (Type)index;
}