mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-28 02:10:06 +00:00
.. half closed range; ... open range; ... variadic syntax
This commit is contained in:
+8
-8
@@ -285,7 +285,7 @@ copy :: proc(dst, src: []$T) -> int #cc_contextless {
|
||||
|
||||
|
||||
|
||||
append :: proc(array: ^[]$T, args: ..T) -> int #cc_contextless {
|
||||
append :: proc(array: ^[]$T, args: ...T) -> int #cc_contextless {
|
||||
if array == nil do return 0;
|
||||
|
||||
arg_len := len(args);
|
||||
@@ -303,7 +303,7 @@ append :: proc(array: ^[]$T, args: ..T) -> int #cc_contextless {
|
||||
return len(array);
|
||||
}
|
||||
|
||||
append :: proc(array: ^[dynamic]$T, args: ..T) -> int {
|
||||
append :: proc(array: ^[dynamic]$T, args: ...T) -> int {
|
||||
if array == nil do return 0;
|
||||
|
||||
arg_len := len(args);
|
||||
@@ -559,21 +559,21 @@ __complex128_ne :: proc(a, b: complex128) -> bool #cc_contextless #inline { retu
|
||||
|
||||
__bounds_check_error :: proc(file: string, line, column: int, index, count: int) #cc_contextless {
|
||||
if 0 <= index && index < count do return;
|
||||
fmt.fprintf(os.stderr, "%s(%d:%d) Index %d is out of bounds range 0..<%d\n",
|
||||
fmt.fprintf(os.stderr, "%s(%d:%d) Index %d is out of bounds range 0..%d\n",
|
||||
file, line, column, index, count);
|
||||
__debug_trap();
|
||||
}
|
||||
|
||||
__slice_expr_error :: proc(file: string, line, column: int, low, high, max: int) #cc_contextless {
|
||||
if 0 <= low && low <= high && high <= max do return;
|
||||
fmt.fprintf(os.stderr, "%s(%d:%d) Invalid slice indices: [%d..<%d..<%d]\n",
|
||||
fmt.fprintf(os.stderr, "%s(%d:%d) Invalid slice indices: [%d..%d..%d]\n",
|
||||
file, line, column, low, high, max);
|
||||
__debug_trap();
|
||||
}
|
||||
|
||||
__substring_expr_error :: proc(file: string, line, column: int, low, high: int) #cc_contextless {
|
||||
if 0 <= low && low <= high do return;
|
||||
fmt.fprintf(os.stderr, "%s(%d:%d) Invalid substring indices: [%d..<%d]\n",
|
||||
fmt.fprintf(os.stderr, "%s(%d:%d) Invalid substring indices: [%d..%d]\n",
|
||||
file, line, column, low, high);
|
||||
__debug_trap();
|
||||
}
|
||||
@@ -623,7 +623,7 @@ __mem_copy_non_overlapping :: proc(dst, src: rawptr, len: int) -> rawptr #cc_con
|
||||
}
|
||||
|
||||
__mem_compare :: proc(a, b: ^u8, n: int) -> int #cc_contextless {
|
||||
for i in 0..<n {
|
||||
for i in 0..n {
|
||||
match {
|
||||
case (a+i)^ < (b+i)^: return -1;
|
||||
case (a+i)^ > (b+i)^: return +1;
|
||||
@@ -791,9 +791,9 @@ __dynamic_map_rehash :: proc(using header: __MapHeader, new_count: int) {
|
||||
|
||||
__dynamic_array_resize(nm_hashes, size_of(int), align_of(int), new_count);
|
||||
__dynamic_array_reserve(&nm.entries, entry_size, entry_align, m.entries.len);
|
||||
for i in 0..<new_count do nm.hashes[i] = -1;
|
||||
for i in 0..new_count do nm.hashes[i] = -1;
|
||||
|
||||
for i := 0; i < m.entries.len; i++ {
|
||||
for i in 0..m.entries.len {
|
||||
if len(nm.hashes) == 0 do __dynamic_map_grow(new_header);
|
||||
|
||||
entry_header := __dynamic_map_get_entry(header, i);
|
||||
|
||||
+9
-9
@@ -20,29 +20,29 @@ decimal_to_string :: proc(buf: []u8, a: ^Decimal) -> string {
|
||||
|
||||
// TODO(bill): make this work with a buffer that's not big enough
|
||||
assert(len(buf) >= n);
|
||||
buf = buf[0..<n];
|
||||
buf = buf[0..n];
|
||||
|
||||
if a.count == 0 {
|
||||
buf[0] = '0';
|
||||
return string(buf[0..<1]);
|
||||
return string(buf[0..1]);
|
||||
}
|
||||
|
||||
w := 0;
|
||||
if a.decimal_point <= 0 {
|
||||
buf[w] = '0'; w++;
|
||||
buf[w] = '.'; w++;
|
||||
w += digit_zero(buf[w ..< w-a.decimal_point]);
|
||||
w += copy(buf[w..], a.digits[0..<a.count]);
|
||||
w += digit_zero(buf[w .. w-a.decimal_point]);
|
||||
w += copy(buf[w..], a.digits[0..a.count]);
|
||||
} else if a.decimal_point < a.count {
|
||||
w += copy(buf[w..], a.digits[0..<a.decimal_point]);
|
||||
w += copy(buf[w..], a.digits[0..a.decimal_point]);
|
||||
buf[w] = '.'; w++;
|
||||
w += copy(buf[w..], a.digits[a.decimal_point ..< a.count]);
|
||||
w += copy(buf[w..], a.digits[a.decimal_point .. a.count]);
|
||||
} else {
|
||||
w += copy(buf[w..], a.digits[0..<a.count]);
|
||||
w += digit_zero(buf[w ..< w+a.decimal_point-a.count]);
|
||||
w += copy(buf[w..], a.digits[0..a.count]);
|
||||
w += digit_zero(buf[w .. w+a.decimal_point-a.count]);
|
||||
}
|
||||
|
||||
return string(buf[0..<w]);
|
||||
return string(buf[0..w]);
|
||||
}
|
||||
|
||||
// trim trailing zeros
|
||||
|
||||
+51
-51
@@ -70,9 +70,9 @@ write_string :: proc(buf: ^StringBuffer, s: string) {
|
||||
write_bytes :: proc(buf: ^StringBuffer, data: []u8) {
|
||||
match b in buf {
|
||||
case StringBuffer.Static:
|
||||
append(&b.buf, ..data);
|
||||
append(&b.buf, ...data);
|
||||
case StringBuffer.Dynamic:
|
||||
append(&b.buf, ..data);
|
||||
append(&b.buf, ...data);
|
||||
}
|
||||
}
|
||||
write_byte :: proc(buf: ^StringBuffer, data: u8) {
|
||||
@@ -90,43 +90,43 @@ write_rune :: proc(buf: ^StringBuffer, r: rune) {
|
||||
}
|
||||
|
||||
b, n := utf8.encode_rune(r);
|
||||
write_bytes(buf, b[0..<n]);
|
||||
write_bytes(buf, b[..n]);
|
||||
}
|
||||
|
||||
write_int :: proc(buf: ^StringBuffer, i: i128, base: int) {
|
||||
b: [129]u8;
|
||||
s := strconv.append_bits(b[0..<0], u128(i), base, true, 128, strconv.digits, 0);
|
||||
s := strconv.append_bits(b[..0], u128(i), base, true, 128, strconv.digits, 0);
|
||||
write_string(buf, s);
|
||||
}
|
||||
write_int :: proc(buf: ^StringBuffer, i: i64, base: int) {
|
||||
b: [129]u8;
|
||||
s := strconv.append_bits(b[0..<0], u128(i), base, true, 64, strconv.digits, 0);
|
||||
s := strconv.append_bits(b[..0], u128(i), base, true, 64, strconv.digits, 0);
|
||||
write_string(buf, s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
fprint :: proc(fd: os.Handle, args: ..any) -> int {
|
||||
fprint :: proc(fd: os.Handle, args: ...any) -> int {
|
||||
data: [_BUFFER_SIZE]u8;
|
||||
buf := make_string_buffer_from_slice(data[0..<0]);
|
||||
sbprint(&buf, ..args);
|
||||
buf := make_string_buffer_from_slice(data[..0]);
|
||||
sbprint(&buf, ...args);
|
||||
res := string_buffer_data(buf);
|
||||
os.write(fd, res);
|
||||
return len(res);
|
||||
}
|
||||
|
||||
fprintln :: proc(fd: os.Handle, args: ..any) -> int {
|
||||
fprintln :: proc(fd: os.Handle, args: ...any) -> int {
|
||||
data: [_BUFFER_SIZE]u8;
|
||||
buf := make_string_buffer_from_slice(data[0..<0]);
|
||||
sbprintln(&buf, ..args);
|
||||
buf := make_string_buffer_from_slice(data[..0]);
|
||||
sbprintln(&buf, ...args);
|
||||
res := string_buffer_data(buf);
|
||||
os.write(fd, res);
|
||||
return len(res);
|
||||
}
|
||||
fprintf :: proc(fd: os.Handle, fmt: string, args: ..any) -> int {
|
||||
fprintf :: proc(fd: os.Handle, fmt: string, args: ...any) -> int {
|
||||
data: [_BUFFER_SIZE]u8;
|
||||
buf := make_string_buffer_from_slice(data[0..<0]);
|
||||
sbprintf(&buf, fmt, ..args);
|
||||
buf := make_string_buffer_from_slice(data[..0]);
|
||||
sbprintf(&buf, fmt, ...args);
|
||||
res := string_buffer_data(buf);
|
||||
os.write(fd, res);
|
||||
return len(res);
|
||||
@@ -134,46 +134,46 @@ fprintf :: proc(fd: os.Handle, fmt: string, args: ..any) -> int {
|
||||
|
||||
|
||||
// print* procedures return the number of bytes written
|
||||
print :: proc(args: ..any) -> int { return fprint(os.stdout, ..args); }
|
||||
print_err :: proc(args: ..any) -> int { return fprint(os.stderr, ..args); }
|
||||
println :: proc(args: ..any) -> int { return fprintln(os.stdout, ..args); }
|
||||
println_err :: proc(args: ..any) -> int { return fprintln(os.stderr, ..args); }
|
||||
printf :: proc(fmt: string, args: ..any) -> int { return fprintf(os.stdout, fmt, ..args); }
|
||||
printf_err :: proc(fmt: string, args: ..any) -> int { return fprintf(os.stderr, fmt, ..args); }
|
||||
print :: proc(args: ...any) -> int { return fprint(os.stdout, ...args); }
|
||||
print_err :: proc(args: ...any) -> int { return fprint(os.stderr, ...args); }
|
||||
println :: proc(args: ...any) -> int { return fprintln(os.stdout, ...args); }
|
||||
println_err :: proc(args: ...any) -> int { return fprintln(os.stderr, ...args); }
|
||||
printf :: proc(fmt: string, args: ...any) -> int { return fprintf(os.stdout, fmt, ...args); }
|
||||
printf_err :: proc(fmt: string, args: ...any) -> int { return fprintf(os.stderr, fmt, ...args); }
|
||||
|
||||
|
||||
// aprint* procedures return a string that was allocated with the current context
|
||||
// They must be freed accordingly
|
||||
aprint :: proc(args: ..any) -> string {
|
||||
aprint :: proc(args: ...any) -> string {
|
||||
buf := make_string_dynamic_buffer();
|
||||
sbprint(&buf, ..args);
|
||||
sbprint(&buf, ...args);
|
||||
return to_string(buf);
|
||||
}
|
||||
aprintln :: proc(args: ..any) -> string {
|
||||
aprintln :: proc(args: ...any) -> string {
|
||||
buf := make_string_dynamic_buffer();
|
||||
sbprintln(&buf, ..args);
|
||||
sbprintln(&buf, ...args);
|
||||
return to_string(buf);
|
||||
}
|
||||
aprintf :: proc(fmt: string, args: ..any) -> string {
|
||||
aprintf :: proc(fmt: string, args: ...any) -> string {
|
||||
buf := make_string_dynamic_buffer();
|
||||
sbprintf(&buf, fmt, ..args);
|
||||
sbprintf(&buf, fmt, ...args);
|
||||
return to_string(buf);
|
||||
}
|
||||
|
||||
|
||||
// bprint* procedures return a string that was allocated with the current context
|
||||
// They must be freed accordingly
|
||||
bprint :: proc(buf: []u8, args: ..any) -> string {
|
||||
sb := make_string_buffer_from_slice(buf[0..<0..<len(buf)]);
|
||||
return sbprint(&sb, ..args);
|
||||
bprint :: proc(buf: []u8, args: ...any) -> string {
|
||||
sb := make_string_buffer_from_slice(buf[..0..len(buf)]);
|
||||
return sbprint(&sb, ...args);
|
||||
}
|
||||
bprintln :: proc(buf: []u8, args: ..any) -> string {
|
||||
sb := make_string_buffer_from_slice(buf[0..<0..<len(buf)]);
|
||||
return sbprintln(&sb, ..args);
|
||||
bprintln :: proc(buf: []u8, args: ...any) -> string {
|
||||
sb := make_string_buffer_from_slice(buf[..0..len(buf)]);
|
||||
return sbprintln(&sb, ...args);
|
||||
}
|
||||
bprintf :: proc(buf: []u8, fmt: string, args: ..any) -> string {
|
||||
sb := make_string_buffer_from_slice(buf[0..<0..<len(buf)]);
|
||||
return sbprintf(&sb, fmt, ..args);
|
||||
bprintf :: proc(buf: []u8, fmt: string, args: ...any) -> string {
|
||||
sb := make_string_buffer_from_slice(buf[..0..len(buf)]);
|
||||
return sbprintf(&sb, fmt, ...args);
|
||||
}
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ bprintf :: proc(buf: []u8, fmt: string, args: ..any) -> string {
|
||||
|
||||
fprint_type :: proc(fd: os.Handle, info: ^TypeInfo) {
|
||||
data: [_BUFFER_SIZE]u8;
|
||||
buf := make_string_buffer_from_slice(data[0..<0]);
|
||||
buf := make_string_buffer_from_slice(data[..0]);
|
||||
write_type(&buf, info);
|
||||
os.write(fd, string_buffer_data(buf));
|
||||
}
|
||||
@@ -328,7 +328,7 @@ write_type :: proc(buf: ^StringBuffer, ti: ^TypeInfo) {
|
||||
variant := variant_type.(^Struct);
|
||||
|
||||
vc := len(variant.names)-len(cf.names);
|
||||
for j in 0..<vc {
|
||||
for j in 0..vc {
|
||||
if j > 0 do write_string(buf, ", ");
|
||||
index := j + len(cf.names);
|
||||
write_string(buf, variant.names[index]);
|
||||
@@ -404,7 +404,7 @@ _arg_number :: proc(fi: ^FmtInfo, arg_index: int, format: string, offset, arg_co
|
||||
return 0, 1, false;
|
||||
}
|
||||
|
||||
for i in 1..len(format) {
|
||||
for i in 1...len(format) {
|
||||
if format[i] == ']' {
|
||||
width, new_index, ok := _parse_int(format, 1);
|
||||
if !ok || new_index != i {
|
||||
@@ -486,7 +486,7 @@ fmt_write_padding :: proc(fi: ^FmtInfo, width: int) {
|
||||
|
||||
pad_byte: u8 = fi.space ? ' ' : '0';
|
||||
|
||||
for _ in 0..<width {
|
||||
for _ in 0..width {
|
||||
write_byte(fi.buf, pad_byte);
|
||||
}
|
||||
}
|
||||
@@ -535,7 +535,7 @@ _fmt_int :: proc(fi: ^FmtInfo, u: u128, base: int, is_signed: bool, bit_size: in
|
||||
if fi.hash && !fi.zero do flags |= strconv.IntFlag.Prefix;
|
||||
if fi.plus do flags |= strconv.IntFlag.Plus;
|
||||
if fi.space do flags |= strconv.IntFlag.Space;
|
||||
s := strconv.append_bits(buf[start..<start], u128(u), base, is_signed, bit_size, digits, flags);
|
||||
s := strconv.append_bits(buf[start..start], u128(u), base, is_signed, bit_size, digits, flags);
|
||||
|
||||
if fi.hash && fi.zero {
|
||||
c: u8;
|
||||
@@ -622,8 +622,8 @@ fmt_float :: proc(fi: ^FmtInfo, v: f64, bit_size: int, verb: rune) {
|
||||
prec: int = fi.prec_set ? fi.prec : 3;
|
||||
buf: [386]u8;
|
||||
|
||||
str := strconv.append_float(buf[1..<1], v, 'f', prec, bit_size);
|
||||
str = string(buf[0..len(str)]);
|
||||
str := strconv.append_float(buf[1..1], v, 'f', prec, bit_size);
|
||||
str = string(buf[...len(str)]);
|
||||
if str[1] == '+' || str[1] == '-' {
|
||||
str = str[1..];
|
||||
} else {
|
||||
@@ -665,7 +665,7 @@ fmt_string :: proc(fi: ^FmtInfo, s: string, verb: rune) {
|
||||
fi.space = false;
|
||||
defer fi.space = space;
|
||||
|
||||
for i in 0..<len(s) {
|
||||
for i in 0..len(s) {
|
||||
if i > 0 && space do write_byte(fi.buf, ' ');
|
||||
_fmt_int(fi, u128(s[i]), 16, false, 8, verb == 'x' ? __DIGITS_LOWER : __DIGITS_UPPER);
|
||||
}
|
||||
@@ -812,7 +812,7 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
||||
case Array:
|
||||
write_byte(fi.buf, '[');
|
||||
defer write_byte(fi.buf, ']');
|
||||
for i in 0..<info.count {
|
||||
for i in 0..info.count {
|
||||
if i > 0 do write_string(fi.buf, ", ");
|
||||
|
||||
data := ^u8(v.data) + i*info.elem_size;
|
||||
@@ -823,7 +823,7 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
||||
write_byte(fi.buf, '[');
|
||||
defer write_byte(fi.buf, ']');
|
||||
array := ^raw.DynamicArray(v.data);
|
||||
for i in 0..<array.len {
|
||||
for i in 0..array.len {
|
||||
if i > 0 do write_string(fi.buf, ", ");
|
||||
|
||||
data := ^u8(array.data) + i*info.elem_size;
|
||||
@@ -845,7 +845,7 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
||||
write_byte(fi.buf, '<');
|
||||
defer write_byte(fi.buf, '>');
|
||||
|
||||
for i in 0..<info.count {
|
||||
for i in 0..info.count {
|
||||
if i > 0 do write_string(fi.buf, ", ");
|
||||
|
||||
data := ^u8(v.data) + i*info.elem_size;
|
||||
@@ -867,7 +867,7 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
||||
entry_type := ed.elem.(^Struct);
|
||||
entry_size := ed.elem_size;
|
||||
|
||||
for i in 0..<entries.len {
|
||||
for i in 0..entries.len {
|
||||
if i > 0 do write_string(fi.buf, ", ");
|
||||
|
||||
data := ^u8(entries.data) + i*entry_size;
|
||||
@@ -1008,7 +1008,7 @@ fmt_arg :: proc(fi: ^FmtInfo, arg: any, verb: rune) {
|
||||
|
||||
|
||||
|
||||
sbprint :: proc(buf: ^StringBuffer, args: ..any) -> string {
|
||||
sbprint :: proc(buf: ^StringBuffer, args: ...any) -> string {
|
||||
fi: FmtInfo;
|
||||
prev_string := false;
|
||||
|
||||
@@ -1025,7 +1025,7 @@ sbprint :: proc(buf: ^StringBuffer, args: ..any) -> string {
|
||||
return to_string(buf^);
|
||||
}
|
||||
|
||||
sbprintln :: proc(buf: ^StringBuffer, args: ..any) -> string {
|
||||
sbprintln :: proc(buf: ^StringBuffer, args: ...any) -> string {
|
||||
fi: FmtInfo;
|
||||
fi.buf = buf;
|
||||
|
||||
@@ -1038,7 +1038,7 @@ sbprintln :: proc(buf: ^StringBuffer, args: ..any) -> string {
|
||||
return to_string(buf^);
|
||||
}
|
||||
|
||||
sbprintf :: proc(b: ^StringBuffer, fmt: string, args: ..any) -> string {
|
||||
sbprintf :: proc(b: ^StringBuffer, fmt: string, args: ...any) -> string {
|
||||
fi: FmtInfo;
|
||||
arg_index: int = 0;
|
||||
end := len(fmt);
|
||||
@@ -1053,7 +1053,7 @@ sbprintf :: proc(b: ^StringBuffer, fmt: string, args: ..any) -> string {
|
||||
i++;
|
||||
}
|
||||
if i > prev_i {
|
||||
write_string(b, fmt[prev_i..<i]);
|
||||
write_string(b, fmt[prev_i..i]);
|
||||
}
|
||||
if i >= end {
|
||||
break;
|
||||
|
||||
+1
-1
@@ -175,7 +175,7 @@ murmur64 :: proc(data: []u8) -> u64 {
|
||||
}
|
||||
|
||||
// TODO(bill): Fix this
|
||||
#no_bounds_check data8 := slice_to_bytes(data32[i..])[0..<3];
|
||||
#no_bounds_check data8 := slice_to_bytes(data32[i..])[..3];
|
||||
match len {
|
||||
case 3:
|
||||
h2 ~= u32(data8[2]) << 16;
|
||||
|
||||
+4
-4
@@ -158,8 +158,8 @@ mat4_identity :: proc() -> Mat4 {
|
||||
}
|
||||
|
||||
mat4_transpose :: proc(m: Mat4) -> Mat4 {
|
||||
for j in 0..<4 {
|
||||
for i in 0..<4 {
|
||||
for j in 0..4 {
|
||||
for i in 0..4 {
|
||||
m[i][j], m[j][i] = m[j][i], m[i][j];
|
||||
}
|
||||
}
|
||||
@@ -168,8 +168,8 @@ mat4_transpose :: proc(m: Mat4) -> Mat4 {
|
||||
|
||||
mul :: proc(a, b: Mat4) -> Mat4 {
|
||||
c: Mat4;
|
||||
for j in 0..<4 {
|
||||
for i in 0..<4 {
|
||||
for j in 0..4 {
|
||||
for i in 0..4 {
|
||||
c[j][i] = a[0][i]*b[j][0] +
|
||||
a[1][i]*b[j][1] +
|
||||
a[2][i]*b[j][2] +
|
||||
|
||||
+2
-2
@@ -110,7 +110,7 @@ ArenaTempMemory :: struct {
|
||||
|
||||
init_arena_from_memory :: proc(using a: ^Arena, data: []u8) {
|
||||
backing = Allocator{};
|
||||
memory = data[0..<0];
|
||||
memory = data[..0];
|
||||
temp_count = 0;
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ begin_arena_temp_memory :: proc(a: ^Arena) -> ArenaTempMemory {
|
||||
end_arena_temp_memory :: proc(using tmp: ArenaTempMemory) {
|
||||
assert(len(arena.memory) >= original_count);
|
||||
assert(arena.temp_count > 0);
|
||||
arena.memory = arena.memory[0..<original_count];
|
||||
arena.memory = arena.memory[..original_count];
|
||||
arena.temp_count--;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ _libgl := win32.load_library_a(_string_data("opengl32.dll\x00"));
|
||||
|
||||
get_proc_address :: proc(name: string) -> rawptr {
|
||||
if name[len(name)-1] == 0 {
|
||||
name = name[0..<len(name)-1];
|
||||
name = name[..len(name)-1];
|
||||
}
|
||||
// NOTE(bill): null terminated
|
||||
assert((&name[0] + len(name))^ == 0);
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ read_entire_file :: proc(name: string) -> ([]u8, bool) {
|
||||
free(data);
|
||||
return nil, false;
|
||||
}
|
||||
return data[0..<bytes_read], true;
|
||||
return data[0..bytes_read], true;
|
||||
}
|
||||
|
||||
write_entire_file :: proc(name: string, data: []u8) -> bool {
|
||||
|
||||
@@ -301,7 +301,7 @@ _alloc_command_line_arguments :: proc() -> []string {
|
||||
}
|
||||
}
|
||||
|
||||
return string(buf[0..<i]);
|
||||
return string(buf[..i]);
|
||||
}
|
||||
|
||||
arg_count: i32;
|
||||
|
||||
+18
-18
@@ -7,7 +7,7 @@ bubble_sort :: proc(array: []$T, f: proc(T, T) -> int) {
|
||||
for {
|
||||
init_swap, prev_swap := -1, -1;
|
||||
|
||||
for j in init_j..<last_j {
|
||||
for j in init_j..last_j {
|
||||
if f(array[j], array[j+1]) > 0 {
|
||||
array[j], array[j+1] = array[j+1], array[j];
|
||||
prev_swap = j;
|
||||
@@ -30,7 +30,7 @@ bubble_sort :: proc(array: []$T) {
|
||||
for {
|
||||
init_swap, prev_swap := -1, -1;
|
||||
|
||||
for j in init_j..<last_j {
|
||||
for j in init_j..last_j {
|
||||
if array[j] > array[j+1] {
|
||||
array[j], array[j+1] = array[j+1], array[j];
|
||||
prev_swap = j;
|
||||
@@ -65,8 +65,8 @@ quick_sort :: proc(array: []$T, f: proc(T, T) -> int) {
|
||||
j -= 1;
|
||||
}
|
||||
|
||||
quick_sort(a[0..<i], f);
|
||||
quick_sort(a[i..<n], f);
|
||||
quick_sort(a[0..i], f);
|
||||
quick_sort(a[i..n], f);
|
||||
}
|
||||
|
||||
quick_sort :: proc(array: []$T) {
|
||||
@@ -88,8 +88,8 @@ quick_sort :: proc(array: []$T) {
|
||||
j -= 1;
|
||||
}
|
||||
|
||||
quick_sort(a[0..<i]);
|
||||
quick_sort(a[i..<n]);
|
||||
quick_sort(a[0..i]);
|
||||
quick_sort(a[i..n]);
|
||||
}
|
||||
|
||||
_log2 :: proc(n: int) -> int {
|
||||
@@ -102,7 +102,7 @@ merge_sort :: proc(array: []$T, f: proc(T, T) -> int) {
|
||||
merge_slices :: proc(arr1, arr2, out: []$T, f: proc(T, T) -> int) {
|
||||
N1, N2 := len(arr1), len(arr2);
|
||||
i, j := 0, 0;
|
||||
for k in 0..<N1+N2 {
|
||||
for k in 0..N1+N2 {
|
||||
if j == N2 || i < N1 && j < N2 && f(arr1[i], arr2[j]) < 0 {
|
||||
out[k] = arr1[i]; i++;
|
||||
} else {
|
||||
@@ -120,16 +120,16 @@ merge_sort :: proc(array: []$T, f: proc(T, T) -> int) {
|
||||
|
||||
a, b, m, M := N/2, N, 1, _log2(N);
|
||||
|
||||
for i in 0..<M+1 {
|
||||
for j in 0..<a {
|
||||
for i in 0..M+1 {
|
||||
for j in 0..a {
|
||||
k := 2*j*m;
|
||||
merge_slices(arr1[k..<k+m], arr1[k+m..<k+m+m], arr2[k..], f);
|
||||
merge_slices(arr1[k..k+m], arr1[k+m..k+m+m], arr2[k..], f);
|
||||
}
|
||||
if N-b > m {
|
||||
k := 2*a*m;
|
||||
merge_slices(arr1[k..<k+m], arr1[k+m..<k+m+(N-b)&(m-1)], arr2[k..], f);
|
||||
merge_slices(arr1[k..k+m], arr1[k+m..k+m+(N-b)&(m-1)], arr2[k..], f);
|
||||
} else {
|
||||
copy(arr2[b..N-1], arr1[b..N-1]);
|
||||
copy(arr2[b..N], arr1[b..N]);
|
||||
}
|
||||
arr1, arr2 = arr2, arr1;
|
||||
m <<= 1;
|
||||
@@ -144,7 +144,7 @@ merge_sort :: proc(array: []$T) {
|
||||
merge_slices :: proc(arr1, arr2, out: []$T) {
|
||||
N1, N2 := len(arr1), len(arr2);
|
||||
i, j := 0, 0;
|
||||
for k in 0..<N1+N2 {
|
||||
for k in 0..N1+N2 {
|
||||
if j == N2 || i < N1 && j < N2 && arr1[i] < arr2[j] {
|
||||
out[k] = arr1[i]; i++;
|
||||
} else {
|
||||
@@ -160,16 +160,16 @@ merge_sort :: proc(array: []$T) {
|
||||
|
||||
a, b, m, M := N/2, N, 1, _log2(N);
|
||||
|
||||
for i in 0..<M+1 {
|
||||
for j in 0..<a {
|
||||
for i in 0..M+1 {
|
||||
for j in 0..a {
|
||||
k := 2*j*m;
|
||||
merge_slices(arr1[k..<k+m], arr1[k+m..<k+m+m], arr2[k..]);
|
||||
merge_slices(arr1[k..k+m], arr1[k+m..k+m+m], arr2[k..]);
|
||||
}
|
||||
if N-b > m {
|
||||
k := 2*a*m;
|
||||
merge_slices(arr1[k..<k+m], arr1[k+m..<k+m+(N-b)&(m-1)], arr2[k..]);
|
||||
merge_slices(arr1[k..k+m], arr1[k+m..k+m+(N-b)&(m-1)], arr2[k..]);
|
||||
} else {
|
||||
copy(arr2[b..N-1], arr1[b..N-1]);
|
||||
copy(arr2[b..N], arr1[b..N]);
|
||||
}
|
||||
arr1, arr2 = arr2, arr1;
|
||||
m <<= 1;
|
||||
|
||||
+7
-7
@@ -191,7 +191,7 @@ parse_f64 :: proc(s: string) -> f64 {
|
||||
|
||||
append_bool :: proc(buf: []u8, b: bool) -> string {
|
||||
s := b ? "true" : "false";
|
||||
append(&buf, ..[]u8(s));
|
||||
append(&buf, ...[]u8(s));
|
||||
return string(buf);
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ generic_ftoa :: proc(buf: []u8, val: f64, fmt: u8, prec, bit_size: int) -> []u8
|
||||
} else {
|
||||
s = "+Inf";
|
||||
}
|
||||
append(&buf, ..[]u8(s));
|
||||
append(&buf, ...[]u8(s));
|
||||
return buf;
|
||||
|
||||
case 0: // denormalized
|
||||
@@ -309,7 +309,7 @@ format_digits :: proc(buf: []u8, shortest: bool, neg: bool, digs: DecimalSlice,
|
||||
// integer, padded with zeros when needed
|
||||
if digs.decimal_point > 0 {
|
||||
m := min(digs.count, digs.decimal_point);
|
||||
append(&buf, ..digs.digits[0..<m]);
|
||||
append(&buf, ...digs.digits[..m]);
|
||||
for ; m < digs.decimal_point; m++ {
|
||||
append(&buf, '0');
|
||||
}
|
||||
@@ -321,7 +321,7 @@ format_digits :: proc(buf: []u8, shortest: bool, neg: bool, digs: DecimalSlice,
|
||||
// fractional part
|
||||
if prec > 0 {
|
||||
append(&buf, '.');
|
||||
for i in 0..<prec {
|
||||
for i in 0..prec {
|
||||
c: u8 = '0';
|
||||
if j := digs.decimal_point + i; 0 <= j && j < digs.count {
|
||||
c = digs.digits[j];
|
||||
@@ -342,7 +342,7 @@ format_digits :: proc(buf: []u8, shortest: bool, neg: bool, digs: DecimalSlice,
|
||||
}
|
||||
|
||||
c := [2]u8{'%', fmt};
|
||||
append(&buf, ..c[..]);
|
||||
append(&buf, ...c[..]);
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -383,7 +383,7 @@ round_shortest :: proc(d: ^Decimal, mant: u64, exp: int, flt: ^Float_Info) {
|
||||
|
||||
inclusive := mant%2 == 0;
|
||||
|
||||
for i in 0..<d.count {
|
||||
for i in 0..d.count {
|
||||
l: u8 = '0'; // lower digit
|
||||
if i < lower.count {
|
||||
l = lower.digits[i];
|
||||
@@ -492,7 +492,7 @@ append_bits :: proc(buf: []u8, u: u128, base: int, is_signed: bool, bit_size: in
|
||||
i--; a[i] = ' ';
|
||||
}
|
||||
|
||||
append(&buf, ..a[i..]);
|
||||
append(&buf, ...a[i..]);
|
||||
return string(buf);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ new_string :: proc(s: string) -> string {
|
||||
c := make([]u8, len(s)+1);
|
||||
copy(c, []u8(s));
|
||||
c[len(s)] = 0;
|
||||
return string(c[0..<len(s)]);
|
||||
return string(c[..len(s)]);
|
||||
}
|
||||
|
||||
new_c_string :: proc(s: string) -> ^u8 {
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ encode :: proc(d: []u16, s: []rune) {
|
||||
|
||||
for r in s {
|
||||
match r {
|
||||
case 0..<_surr1, _surr3..<_surr_self:
|
||||
case 0.._surr1, _surr3.._surr_self:
|
||||
d[n] = u16(r);
|
||||
n++;
|
||||
|
||||
|
||||
+1
-1
@@ -160,7 +160,7 @@ decode_last_rune :: proc(s: []u8) -> (rune, int) {
|
||||
}
|
||||
|
||||
start = max(start, 0);
|
||||
r, size = decode_rune(s[start..<end]);
|
||||
r, size = decode_rune(s[start..end]);
|
||||
if start+size != end {
|
||||
return RUNE_ERROR, 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user