i had more code but the compiler said no
This commit is contained in:
parent
3045d0a190
commit
2d9dd38380
src
|
@ -39,7 +39,7 @@ HashMap := fn($Key: type, $Value: type, $Hasher: type, $Allocator: type): type r
|
|||
|
||||
new := fn(allocator: ^Allocator): Self {
|
||||
hasher := Hasher.default()
|
||||
buckets := Buckets(Key, Value, Allocator).new_with_capacity(allocator, 16)
|
||||
buckets := Buckets(Key, Value, Allocator).with_capacity(allocator, 16)
|
||||
// ! (compiler) bug: have to use for-loop here rather than using buckets.len(), otherwise we loop infinitely
|
||||
i := 0
|
||||
loop if i == 16 break else {
|
||||
|
@ -53,7 +53,7 @@ HashMap := fn($Key: type, $Value: type, $Hasher: type, $Allocator: type): type r
|
|||
// seems like bad performance...
|
||||
resize := fn(self: ^Self): void {
|
||||
new_cap := next_power_of_two(self.buckets.len() * 2)
|
||||
new_buckets := @TypeOf(self.buckets).new_with_capacity(self.allocator, new_cap)
|
||||
new_buckets := @TypeOf(self.buckets).with_capacity(self.allocator, new_cap)
|
||||
// same compiler bug as above...
|
||||
i := 0
|
||||
loop if i == new_cap break else {
|
||||
|
|
|
@ -5,7 +5,7 @@ Vec := fn($T: type, $Allocator: type): type return struct {
|
|||
allocator: ^Allocator,
|
||||
cap: uint = 0,
|
||||
$new := fn(allocator: ^Allocator): Self return .{slice: Type([]T).uninit(), allocator}
|
||||
$new_with_capacity := fn(allocator: ^Allocator, cap: uint): Self {
|
||||
$with_capacity := fn(allocator: ^Allocator, cap: uint): Self {
|
||||
// ! (libc) (compiler) bug: null check broken, so unwrapping (unsafe!)
|
||||
new_alloc := @unwrap(allocator.alloc(T, cap))
|
||||
return .{slice: new_alloc[0..0], allocator, cap}
|
||||
|
@ -86,12 +86,10 @@ Vec := fn($T: type, $Allocator: type): type return struct {
|
|||
i := 0
|
||||
loop if self.get_unchecked(i) == rhs return i else if i == self.slice.len return null else i += 1
|
||||
}
|
||||
$sort := fn(self: ^Self): void {
|
||||
_ = quicksort(compare, self.slice, 0, self.slice.len - 1)
|
||||
}
|
||||
$sort_with := fn(self: ^Self, $func: type): void {
|
||||
_ = quicksort(func, self.slice, 0, self.slice.len - 1)
|
||||
}
|
||||
$sort := fn(self: ^Self): void self.sort_with(compare)
|
||||
$len := fn(self: ^Self): uint return self.slice.len
|
||||
$capacity := fn(self: ^Self): uint return self.cap
|
||||
}
|
|
@ -38,7 +38,9 @@ main := fn(argc: uint, argv: []^void): uint {
|
|||
|
||||
// return 0
|
||||
|
||||
// ! the following will ONLY work on ableos
|
||||
/* ! the following will ONLY work on ableos
|
||||
* due to fun compiler bugs
|
||||
*/
|
||||
allocator := lily.alloc.SimpleAllocator.new()
|
||||
defer allocator.deinit()
|
||||
map := lily.collections.HashMap(
|
||||
|
|
Loading…
Reference in a new issue