Improve proc group scoring algorithm

This commit is contained in:
gingerBill
2018-08-21 14:11:18 +01:00
parent a4d0ac1802
commit cbc6c2666b
4 changed files with 112 additions and 37 deletions
+10 -9
View File
@@ -24,6 +24,7 @@ Allocator :: struct {
alloc_with_allocator :: inline proc(a: Allocator, size: int, alignment: int = DEFAULT_ALIGNMENT, loc := #caller_location) -> rawptr {
if size == 0 do return nil;
return a.procedure(a.data, Allocator_Mode.Alloc, size, alignment, nil, 0, 0, loc);
}
alloc :: inline proc(size: int, alignment: int = DEFAULT_ALIGNMENT, loc := #caller_location) -> rawptr {
@@ -45,6 +46,10 @@ free_all :: inline proc(loc := #caller_location) {
}
resize_with_allocator :: inline proc(a: Allocator, ptr: rawptr, old_size, new_size: int, alignment: int = DEFAULT_ALIGNMENT, loc := #caller_location) -> rawptr {
if new_size == 0 {
free_ptr_with_allocator(a, ptr, loc);
return nil;
}
return a.procedure(a.data, Allocator_Mode.Resize, new_size, alignment, ptr, old_size, 0, loc);
}
resize :: inline proc(ptr: rawptr, old_size, new_size: int, alignment: int = DEFAULT_ALIGNMENT, loc := #caller_location) -> rawptr {
@@ -82,33 +87,30 @@ delete :: proc[
new :: inline proc(T: type, loc := #caller_location) -> ^T {
ptr := (^T)(alloc(size_of(T), align_of(T), loc));
ptr^ = T{};
if ptr != nil do ptr^ = T{};
return ptr;
}
new_clone :: inline proc(data: $T, loc := #caller_location) -> ^T {
ptr := (^T)(alloc(size_of(T), align_of(T), loc));
ptr^ = data;
if ptr != nil do ptr^ = data;
return ptr;
}
new_with_allocator :: inline proc(a: Allocator, T: type, loc := #caller_location) -> ^T {
ptr := (^T)(alloc_with_allocator(a, size_of(T), align_of(T), loc));
ptr^ = T{};
if ptr != nil do ptr^ = T{};
return ptr;
}
new_clone_with_allocator :: inline proc(a: Allocator, data: $T, loc := #caller_location) -> ^T {
ptr := (^T)(alloc_with_allocator(a, size_of(T), align_of(T), loc));
ptr^ = data;
if ptr != nil do ptr^ = data;
return ptr;
}
make_slice :: proc(T: type/[]$E, auto_cast len: int, loc := #caller_location) -> T {
runtime.make_slice_error_loc(loc, len);
if len == 0 {
return nil;
}
data := alloc(size_of(E)*len, align_of(E));
s := Raw_Slice{data, len};
return transmute(T)s;
@@ -121,8 +123,7 @@ make_dynamic_array_len :: proc(T: type/[dynamic]$E, auto_cast len: int, loc := #
}
make_dynamic_array_len_cap :: proc(T: type/[dynamic]$E, auto_cast len: int, auto_cast cap: int, loc := #caller_location) -> T {
runtime.make_dynamic_array_error_loc(loc, len, cap);
data: rawptr;
if cap > 0 do data = alloc(size_of(E)*cap, align_of(E));
data := alloc(size_of(E)*cap, align_of(E));
s := Raw_Dynamic_Array{data, len, cap, context.allocator};
return transmute(T)s;
}
+55 -4
View File
@@ -366,7 +366,27 @@ delete_key :: proc(m: ^$T/map[$K]$V, key: K) {
@(builtin)
append :: proc(array: ^$T/[dynamic]$E, args: ..E, loc := #caller_location) -> int {
append_elem :: proc(array: ^$T/[dynamic]$E, arg: E, loc := #caller_location) -> int {
if array == nil do return 0;
arg_len := 1;
if cap(array) <= len(array)+arg_len {
cap := 2 * cap(array) + max(8, arg_len);
_ = reserve(array, cap, loc);
}
arg_len = min(cap(array)-len(array), arg_len);
if arg_len > 0 {
a := (^mem.Raw_Dynamic_Array)(array);
data := (^E)(a.data);
assert(data != nil);
mem.copy(mem.ptr_offset(data, a.len), &arg, size_of(E));
a.len += arg_len;
}
return len(array);
}
@(builtin)
append_elems :: proc(array: ^$T/[dynamic]$E, args: ..E, loc := #caller_location) -> int {
if array == nil do return 0;
arg_len := len(args);
@@ -387,6 +407,9 @@ append :: proc(array: ^$T/[dynamic]$E, args: ..E, loc := #caller_location) -> in
}
return len(array);
}
@(builtin) append :: proc[append_elem, append_elems];
@(builtin)
append_string :: proc(array: ^$T/[dynamic]$E/u8, args: ..string, loc := #caller_location) -> int {
@@ -428,14 +451,42 @@ reserve_dynamic_array :: proc(array: ^$T/[dynamic]$E, capacity: int, loc := #cal
return true;
}
@(builtin)
incl :: inline proc(s: ^$B/bit_set[$T], elem: T) {
incl_elem :: inline proc(s: ^$S/bit_set[$E; $U], elem: E) -> S {
s^ |= {elem};
return s^;
}
@(builtin)
excl :: inline proc(s: ^$B/bit_set[$T], elem: T) {
s^ &~= {elem};
incl_elems :: inline proc(s: ^$S/bit_set[$E; $U], elems: ..E) -> S {
for elem in elems do s^ |= {elem};
return s^;
}
@(builtin)
incl_bit_set :: inline proc(s: ^$S/bit_set[$E; $U], other: S) -> S {
s^ |= other;
return s^;
}
@(builtin)
excl_elem :: inline proc(s: ^$S/bit_set[$E; $U], elem: E) -> S {
s^ &~= {elem};
return s^;
}
@(builtin)
excl_elems :: inline proc(s: ^$S/bit_set[$E; $U], elems: ..E) -> S {
for elem in elems do s^ &~= {elem};
return s^;
}
@(builtin)
excl_bit_set :: inline proc(s: ^$S/bit_set[$E; $U], other: S) -> S {
s^ &~= other;
return s^;
}
@(builtin) incl :: proc[incl_elem, incl_elems, incl_bit_set];
@(builtin) excl :: proc[excl_elem, excl_elems, excl_bit_set];