mutable decl syntax change
This commit is contained in:
@@ -21,9 +21,9 @@ task_list_init func(allocator mem.Allocator) TaskList {
|
||||
}
|
||||
|
||||
alloc_i32s func(allocator mem.Allocator, count usize) ?[]mut i32 {
|
||||
fallback [1]mut i32 = undefined
|
||||
failed bool = false
|
||||
values []mut i32 = mem.alloc(allocator, count) catch |_| {
|
||||
fallback [1]mut i32 := undefined
|
||||
failed bool := false
|
||||
values []mut i32 := mem.alloc(allocator, count) catch |_| {
|
||||
failed = true
|
||||
yield (&fallback).ptr[..0]
|
||||
}
|
||||
@@ -42,14 +42,14 @@ task_list_reserve func(list @mut TaskList, capacity usize) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
new_ids ?[]mut i32 = alloc_i32s(list.allocator, capacity)
|
||||
new_priorities ?[]mut i32 = alloc_i32s(list.allocator, capacity)
|
||||
new_durations ?[]mut i32 = alloc_i32s(list.allocator, capacity)
|
||||
new_ids ?[]mut i32 := alloc_i32s(list.allocator, capacity)
|
||||
new_priorities ?[]mut i32 := alloc_i32s(list.allocator, capacity)
|
||||
new_durations ?[]mut i32 := alloc_i32s(list.allocator, capacity)
|
||||
|
||||
if (new_ids and new_priorities and new_durations) |ids, priorities, durations| {
|
||||
if list.len > 0 {
|
||||
if (list.ids and list.priorities and list.durations) |old_ids, old_priorities, old_durations| {
|
||||
i usize = 0
|
||||
i usize := 0
|
||||
while i < list.len : i += 1 {
|
||||
ids[i] = old_ids[i]
|
||||
priorities[i] = old_priorities[i]
|
||||
@@ -82,7 +82,7 @@ task_list_reserve func(list @mut TaskList, capacity usize) bool {
|
||||
|
||||
task_list_push func(list @mut TaskList, id i32, priority i32, duration i32) bool {
|
||||
if list.len == list.capacity {
|
||||
new_capacity usize = 2
|
||||
new_capacity usize := 2
|
||||
if list.capacity != 0 {
|
||||
new_capacity = list.capacity * 2
|
||||
}
|
||||
@@ -92,7 +92,7 @@ task_list_push func(list @mut TaskList, id i32, priority i32, duration i32) bool
|
||||
}
|
||||
|
||||
if (list.ids and list.priorities and list.durations) |ids, priorities, durations| {
|
||||
index usize = list.len
|
||||
index usize := list.len
|
||||
ids[index] = id
|
||||
priorities[index] = priority
|
||||
durations[index] = duration
|
||||
@@ -113,11 +113,11 @@ task_list_best_id func(list @mut TaskList) i32 {
|
||||
}
|
||||
|
||||
if (list.ids and list.priorities and list.durations) |ids, priorities, durations| {
|
||||
best_index usize = 0
|
||||
best_score i32 = task_score(priorities[0], durations[0])
|
||||
i usize = 1
|
||||
best_index usize := 0
|
||||
best_score i32 := task_score(priorities[0], durations[0])
|
||||
i usize := 1
|
||||
while i < list.len : i += 1 {
|
||||
score i32 = task_score(priorities[i], durations[i])
|
||||
score i32 := task_score(priorities[i], durations[i])
|
||||
if score > best_score {
|
||||
best_score = score
|
||||
best_index = i
|
||||
@@ -130,9 +130,9 @@ task_list_best_id func(list @mut TaskList) i32 {
|
||||
}
|
||||
|
||||
task_list_total_duration func(list @mut TaskList) i32 {
|
||||
total i32 = 0
|
||||
total i32 := 0
|
||||
if list.durations |durations| {
|
||||
i usize = 0
|
||||
i usize := 0
|
||||
while i < list.len : i += 1 {
|
||||
total += durations[i]
|
||||
}
|
||||
@@ -152,7 +152,7 @@ task_list_deinit func(list @mut TaskList) void {
|
||||
}
|
||||
|
||||
task_list_test func() i32 {
|
||||
tasks TaskList = task_list_init(mem.c_allocator)
|
||||
tasks TaskList := task_list_init(mem.c_allocator)
|
||||
defer task_list_deinit(&tasks)
|
||||
|
||||
if task_list_push(&tasks, 101, 3, 5) == false {
|
||||
|
||||
Reference in New Issue
Block a user