fixed formatting fuckups offered by the zed team
This commit is contained in:
parent
0db858e814
commit
5a89e9ec7d
60
src/cache.c3
60
src/cache.c3
@ -24,10 +24,10 @@ def IdTableEntry = map::Entry(<Key, usz>) @private;
|
|||||||
const usz CACHE_NCYCLES = (usz)(SIZE * 2.0/3.0);
|
const usz CACHE_NCYCLES = (usz)(SIZE * 2.0/3.0);
|
||||||
|
|
||||||
struct Cache {
|
struct Cache {
|
||||||
BitArr present, used;
|
BitArr present, used;
|
||||||
IdTable table;
|
IdTable table;
|
||||||
Value[] pool;
|
Value[] pool;
|
||||||
usz cycle_count;
|
usz cycle_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Every CACHE_CYCLES operations mark as not-present the unused elements
|
// Every CACHE_CYCLES operations mark as not-present the unused elements
|
||||||
@ -44,32 +44,32 @@ macro Cache.cycle(&cache) @private {
|
|||||||
|
|
||||||
fn void! Cache.init(&cache)
|
fn void! Cache.init(&cache)
|
||||||
{
|
{
|
||||||
cache.table.new_init(capacity: SIZE);
|
cache.table.new_init(capacity: SIZE);
|
||||||
// FIXME: this shit is SLOW
|
// FIXME: this shit is SLOW
|
||||||
foreach (idx, bit : cache.used) { cache.used[idx] = false; }
|
foreach (idx, bit : cache.used) { cache.used[idx] = false; }
|
||||||
foreach (idx, bit : cache.present) { cache.present[idx] = false; }
|
foreach (idx, bit : cache.present) { cache.present[idx] = false; }
|
||||||
cache.pool = mem::new_array(Value, SIZE);
|
cache.pool = mem::new_array(Value, SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn void Cache.free(&cache)
|
fn void Cache.free(&cache)
|
||||||
{
|
{
|
||||||
(void)cache.table.free();
|
(void)cache.table.free();
|
||||||
(void)mem::free(cache.pool);
|
(void)mem::free(cache.pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn Value*! Cache.search(&cache, Key id)
|
fn Value*! Cache.search(&cache, Key id)
|
||||||
{
|
{
|
||||||
// get_entry() faults on miss
|
// get_entry() faults on miss
|
||||||
IdTableEntry* entry = cache.table.get_entry(id)!;
|
IdTableEntry* entry = cache.table.get_entry(id)!;
|
||||||
|
|
||||||
/* MISS */
|
/* MISS */
|
||||||
if (entry.key != id) {
|
if (entry.key != id) {
|
||||||
return SearchResult.MISSING?;
|
return SearchResult.MISSING?;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* MISS, the data is not valid (not present) */
|
/* MISS, the data is not valid (not present) */
|
||||||
if (!cache.present[entry.value]) {
|
if (!cache.present[entry.value]) {
|
||||||
// if the data is not present but it is still in the table, remove it
|
// if the data is not present but it is still in the table, remove it
|
||||||
cache.table.remove(id)!;
|
cache.table.remove(id)!;
|
||||||
return SearchResult.MISSING?;
|
return SearchResult.MISSING?;
|
||||||
}
|
}
|
||||||
@ -83,8 +83,8 @@ fn Value*! Cache.search(&cache, Key id)
|
|||||||
/* If there is no free space left then just return the first position */
|
/* If there is no free space left then just return the first position */
|
||||||
fn usz Cache.get_free_spot(&cache) @private
|
fn usz Cache.get_free_spot(&cache) @private
|
||||||
{
|
{
|
||||||
const BITS = $typeof(cache.present.data[0]).sizeof*8;
|
const BITS = $typeof(cache.present.data[0]).sizeof*8;
|
||||||
foreach (idx, d: cache.present.data) {
|
foreach (idx, d: cache.present.data) {
|
||||||
if (d.clz() != BITS) {
|
if (d.clz() != BITS) {
|
||||||
return idx*BITS + BITS-d.clz();
|
return idx*BITS + BITS-d.clz();
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ fn usz Cache.get_free_spot(&cache) @private
|
|||||||
|
|
||||||
fn Value*! Cache.insert_at(&cache, Value *g, Key id, usz index) @private
|
fn Value*! Cache.insert_at(&cache, Value *g, Key id, usz index) @private
|
||||||
{
|
{
|
||||||
// TODO: verify index, g and id
|
// TODO: verify index, g and id
|
||||||
Value* spot;
|
Value* spot;
|
||||||
|
|
||||||
/* Set used and present */
|
/* Set used and present */
|
||||||
@ -117,17 +117,17 @@ fn Value*! Cache.insert_new(&cache, Value* g, Key id)
|
|||||||
|
|
||||||
fn Value*! Cache.get_or_insert(&cache, Value* g, Key id, bool *is_new = null)
|
fn Value*! Cache.get_or_insert(&cache, Value* g, Key id, bool *is_new = null)
|
||||||
{
|
{
|
||||||
Value*! c = cache.search(id);
|
Value*! c = cache.search(id);
|
||||||
if (catch e = c) {
|
if (catch e = c) {
|
||||||
if (e != SearchResult.MISSING) {
|
if (e != SearchResult.MISSING) {
|
||||||
return e?;
|
return e?;
|
||||||
} else {
|
} else {
|
||||||
// if the element is new (inserted) set the is_new flag
|
// if the element is new (inserted) set the is_new flag
|
||||||
if (is_new) *is_new = true;
|
if (is_new) *is_new = true;
|
||||||
return cache.insert_new(g, id);
|
return cache.insert_new(g, id);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (is_new) *is_new = false;
|
if (is_new) *is_new = false;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
22
src/main.c3
22
src/main.c3
@ -27,7 +27,7 @@ fn int main(String[] args)
|
|||||||
{
|
{
|
||||||
ugui::Ctx ui;
|
ugui::Ctx ui;
|
||||||
ui.init()!!;
|
ui.init()!!;
|
||||||
ui.font.load("/usr/share/fonts/NerdFonts/ttf/HackNerdFont-Regular.ttf", 16, scale: 1.5)!!;
|
ui.font.load("/usr/share/fonts/TTF/HackNerdFontMono-Regular.ttf", 16)!!;
|
||||||
|
|
||||||
short width = 800;
|
short width = 800;
|
||||||
short height = 450;
|
short height = 450;
|
||||||
@ -203,19 +203,19 @@ fn int main(String[] args)
|
|||||||
/*
|
/*
|
||||||
fn void! test_vtree() @test
|
fn void! test_vtree() @test
|
||||||
{
|
{
|
||||||
vtree::VTree(<String>) vt;
|
vtree::VTree(<String>) vt;
|
||||||
vt.init(10)!!;
|
vt.init(10)!!;
|
||||||
defer vt.free();
|
defer vt.free();
|
||||||
|
|
||||||
assert(vt.size() == 10, "Size is incorrect");
|
assert(vt.size() == 10, "Size is incorrect");
|
||||||
|
|
||||||
isz ref = vt.add("Ciao Mamma", 0)!!;
|
isz ref = vt.add("Ciao Mamma", 0)!!;
|
||||||
String s = vt.get(ref)!!;
|
String s = vt.get(ref)!!;
|
||||||
assert(s == "Ciao Mamma", "String is incorrect");
|
assert(s == "Ciao Mamma", "String is incorrect");
|
||||||
isz par = vt.parentof(0)!!;
|
isz par = vt.parentof(0)!!;
|
||||||
assert(ref == par, "Not Root");
|
assert(ref == par, "Not Root");
|
||||||
|
|
||||||
vt.print();
|
vt.print();
|
||||||
}
|
}
|
||||||
|
|
||||||
def StrCache = cache::Cache(<int, String, 256>);
|
def StrCache = cache::Cache(<int, String, 256>);
|
||||||
|
@ -43,7 +43,7 @@ fn void! Ctx.push_rect(&ctx, Rect rect, Color color, bool do_border = false, boo
|
|||||||
// TODO: add texture id
|
// TODO: add texture id
|
||||||
fn void! Ctx.push_sprite(&ctx, Rect bounds, Rect texture)
|
fn void! Ctx.push_sprite(&ctx, Rect bounds, Rect texture)
|
||||||
{
|
{
|
||||||
Cmd cmd = {
|
Cmd cmd = {
|
||||||
.type = CMD_SPRITE,
|
.type = CMD_SPRITE,
|
||||||
.sprite.rect = bounds,
|
.sprite.rect = bounds,
|
||||||
.sprite.texture_rect = texture,
|
.sprite.texture_rect = texture,
|
||||||
@ -56,7 +56,7 @@ fn void! Ctx.push_string(&ctx, Rect bounds, String text)
|
|||||||
if (text.len == 0) {
|
if (text.len == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
short baseline = (short)ctx.font.ascender;
|
short baseline = (short)ctx.font.ascender;
|
||||||
short line_height = (short)ctx.font.ascender - (short)ctx.font.descender;
|
short line_height = (short)ctx.font.ascender - (short)ctx.font.descender;
|
||||||
short line_gap = (short)ctx.font.linegap;
|
short line_gap = (short)ctx.font.linegap;
|
||||||
@ -74,16 +74,16 @@ fn void! Ctx.push_string(&ctx, Rect bounds, String text)
|
|||||||
if (!ascii::is_cntrl((char)cp)) {
|
if (!ascii::is_cntrl((char)cp)) {
|
||||||
gp = ctx.font.get_glyph(cp)!;
|
gp = ctx.font.get_glyph(cp)!;
|
||||||
Rect gb = {
|
Rect gb = {
|
||||||
.x = orig.x + line_len + gp.ox,
|
.x = orig.x + line_len + gp.ox,
|
||||||
.y = orig.y + gp.oy + baseline,
|
.y = orig.y + gp.oy + baseline,
|
||||||
.w = gp.w,
|
.w = gp.w,
|
||||||
.h = gp.h,
|
.h = gp.h,
|
||||||
};
|
};
|
||||||
Rect gt = {
|
Rect gt = {
|
||||||
.x = gp.u,
|
.x = gp.u,
|
||||||
.y = gp.v,
|
.y = gp.v,
|
||||||
.w = gp.w,
|
.w = gp.w,
|
||||||
.h = gp.h,
|
.h = gp.h,
|
||||||
};
|
};
|
||||||
if (rect_collision(gb, bounds)) {
|
if (rect_collision(gb, bounds)) {
|
||||||
ctx.push_sprite(gb, gt)!;
|
ctx.push_sprite(gb, gt)!;
|
||||||
|
@ -71,8 +71,8 @@ struct Div {
|
|||||||
|
|
||||||
// slider element
|
// slider element
|
||||||
struct Slider {
|
struct Slider {
|
||||||
float value;
|
float value;
|
||||||
Rect handle;
|
Rect handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Text {
|
struct Text {
|
||||||
|
@ -12,7 +12,7 @@ fn void! Ctx.div_begin(&ctx, String label, Rect size)
|
|||||||
ctx.active_div = div_node;
|
ctx.active_div = div_node;
|
||||||
|
|
||||||
// 1. Fill the element fields
|
// 1. Fill the element fields
|
||||||
c_elem.type = ETYPE_DIV;
|
c_elem.type = ETYPE_DIV;
|
||||||
|
|
||||||
// do layout and update flags only if the element was updated
|
// do layout and update flags only if the element was updated
|
||||||
if (c_elem.flags.is_new || parent.flags.updated) {
|
if (c_elem.flags.is_new || parent.flags.updated) {
|
||||||
@ -31,8 +31,8 @@ fn void! Ctx.div_begin(&ctx, String label, Rect size)
|
|||||||
c_elem.flags.updated = true;
|
c_elem.flags.updated = true;
|
||||||
// 4. Fill the div fields
|
// 4. Fill the div fields
|
||||||
c_elem.div.origin_c = Point{
|
c_elem.div.origin_c = Point{
|
||||||
.x = c_elem.bounds.x,
|
.x = c_elem.bounds.x,
|
||||||
.y = c_elem.bounds.y,
|
.y = c_elem.bounds.y,
|
||||||
};
|
};
|
||||||
c_elem.div.origin_r = c_elem.div.origin_c;
|
c_elem.div.origin_r = c_elem.div.origin_c;
|
||||||
c_elem.div.layout = parent.div.layout;
|
c_elem.div.layout = parent.div.layout;
|
||||||
|
@ -130,12 +130,12 @@ fn void! Ctx.frame_end(&ctx)
|
|||||||
// draw mouse position
|
// draw mouse position
|
||||||
$if 1:
|
$if 1:
|
||||||
Cmd cmd = {
|
Cmd cmd = {
|
||||||
.type = CMD_RECT,
|
.type = CMD_RECT,
|
||||||
.rect.rect = {
|
.rect.rect = {
|
||||||
.x = ctx.input.mouse.pos.x - 2,
|
.x = ctx.input.mouse.pos.x - 2,
|
||||||
.y = ctx.input.mouse.pos.y - 2,
|
.y = ctx.input.mouse.pos.y - 2,
|
||||||
.w = 4,
|
.w = 4,
|
||||||
.h = 4,
|
.h = 4,
|
||||||
},
|
},
|
||||||
.rect.color = uint_to_rgba(0xff00ffff)
|
.rect.color = uint_to_rgba(0xff00ffff)
|
||||||
};
|
};
|
||||||
|
@ -41,20 +41,9 @@ bitstruct MouseButtons : uint {
|
|||||||
bool btn_5 : 4;
|
bool btn_5 : 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
macro Ctx.mouse_pressed(&ctx)
|
macro Ctx.mouse_pressed(&ctx) => ctx.input.mouse.updated & ctx.input.mouse.down;
|
||||||
{
|
macro Ctx.mouse_released(&ctx) => ctx.input.mouse.updated & ~ctx.input.mouse.down;
|
||||||
return ctx.input.mouse.updated & ctx.input.mouse.down;
|
macro Ctx.mouse_down(&ctx) => ctx.input.mouse.down;
|
||||||
}
|
|
||||||
|
|
||||||
macro Ctx.mouse_released(&ctx)
|
|
||||||
{
|
|
||||||
return ctx.input.mouse.updated & ~ctx.input.mouse.down;
|
|
||||||
}
|
|
||||||
|
|
||||||
macro Ctx.mouse_down(&ctx)
|
|
||||||
{
|
|
||||||
return ctx.input.mouse.down;
|
|
||||||
}
|
|
||||||
|
|
||||||
const MouseButtons BTN_NONE = (MouseButtons)0u;
|
const MouseButtons BTN_NONE = (MouseButtons)0u;
|
||||||
const MouseButtons BTN_ANY = (MouseButtons)(uint.max);
|
const MouseButtons BTN_ANY = (MouseButtons)(uint.max);
|
||||||
@ -66,20 +55,9 @@ const MouseButtons BTN_5 = {.btn_5 = true};
|
|||||||
|
|
||||||
// FIXME: hthis compairson could be done with a cast using MouseButtons.inner
|
// FIXME: hthis compairson could be done with a cast using MouseButtons.inner
|
||||||
// property but I could not figure out how
|
// property but I could not figure out how
|
||||||
macro Ctx.is_mouse_pressed(&ctx, MouseButtons btn)
|
macro Ctx.is_mouse_pressed(&ctx, MouseButtons btn) => (ctx.mouse_pressed() & btn) != BTN_NONE;
|
||||||
{
|
macro Ctx.is_mouse_released(&ctx, MouseButtons btn) => (ctx.mouse_released() & btn) != BTN_NONE;
|
||||||
return (ctx.mouse_pressed() & btn) != BTN_NONE;
|
macro Ctx.is_mouse_down(&ctx, MouseButtons btn) => (ctx.mouse_down() & btn) != BTN_NONE;
|
||||||
}
|
|
||||||
|
|
||||||
macro Ctx.is_mouse_released(&ctx, MouseButtons btn)
|
|
||||||
{
|
|
||||||
return (ctx.mouse_released() & btn) != BTN_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
macro Ctx.is_mouse_down(&ctx, MouseButtons btn)
|
|
||||||
{
|
|
||||||
return (ctx.mouse_down() & btn) != BTN_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
macro ElemEvents Ctx.get_elem_events(&ctx, Elem *elem)
|
macro ElemEvents Ctx.get_elem_events(&ctx, Elem *elem)
|
||||||
{
|
{
|
||||||
|
@ -51,8 +51,8 @@ fn void! Ctx.layout_next_row(&ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
parent.div.origin_r = Point{
|
parent.div.origin_r = Point{
|
||||||
.x = parent.bounds.x,
|
.x = parent.bounds.x,
|
||||||
.y = parent.div.origin_c.y,
|
.y = parent.div.origin_c.y,
|
||||||
};
|
};
|
||||||
parent.div.origin_c = parent.div.origin_r;
|
parent.div.origin_c = parent.div.origin_r;
|
||||||
}
|
}
|
||||||
@ -68,8 +68,8 @@ fn void! Ctx.layout_next_column(&ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
parent.div.origin_c = Point{
|
parent.div.origin_c = Point{
|
||||||
.x = parent.div.origin_r.x,
|
.x = parent.div.origin_r.x,
|
||||||
.y = parent.bounds.y,
|
.y = parent.bounds.y,
|
||||||
};
|
};
|
||||||
parent.div.origin_r = parent.div.origin_c;
|
parent.div.origin_r = parent.div.origin_c;
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ fn void! Ctx.layout_next_column(&ctx)
|
|||||||
*>
|
*>
|
||||||
fn Rect Ctx.position_element(&ctx, Elem *parent, Rect rect, bool style = false)
|
fn Rect Ctx.position_element(&ctx, Elem *parent, Rect rect, bool style = false)
|
||||||
{
|
{
|
||||||
Rect placement;
|
Rect placement;
|
||||||
Point origin;
|
Point origin;
|
||||||
Div* div = &parent.div;
|
Div* div = &parent.div;
|
||||||
|
|
||||||
@ -128,12 +128,12 @@ fn Rect Ctx.position_element(&ctx, Elem *parent, Rect rect, bool style = false)
|
|||||||
|
|
||||||
// 3. Update the origins of the parent
|
// 3. Update the origins of the parent
|
||||||
div.origin_r = Point{
|
div.origin_r = Point{
|
||||||
.x = pl_corner.x,
|
.x = pl_corner.x,
|
||||||
.y = origin.y,
|
.y = origin.y,
|
||||||
};
|
};
|
||||||
div.origin_c = Point{
|
div.origin_c = Point{
|
||||||
.x = origin.x,
|
.x = origin.x,
|
||||||
.y = pl_corner.y,
|
.y = pl_corner.y,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 4. Calculate the "scrolled" view
|
// 4. Calculate the "scrolled" view
|
||||||
|
@ -33,7 +33,7 @@ fn ElemEvents! Ctx.slider_hor(&ctx, String label, Rect size)
|
|||||||
|
|
||||||
c_elem.events = ctx.get_elem_events(c_elem);
|
c_elem.events = ctx.get_elem_events(c_elem);
|
||||||
if (parent.flags.has_focus && c_elem.events.mouse_hover) {
|
if (parent.flags.has_focus && c_elem.events.mouse_hover) {
|
||||||
if (point_in_rect(ctx.input.mouse.pos, c_elem.slider.handle) && c_elem.events.mouse_hold) {
|
if (point_in_rect(ctx.input.mouse.pos, c_elem.slider.handle) && c_elem.events.mouse_hold) {
|
||||||
short x = (short)clamp(ctx.input.mouse.pos.x - c_elem.slider.handle.w/2, c_elem.bounds.x, c_elem.bounds.x + c_elem.bounds.w - c_elem.slider.handle.w);
|
short x = (short)clamp(ctx.input.mouse.pos.x - c_elem.slider.handle.w/2, c_elem.bounds.x, c_elem.bounds.x + c_elem.bounds.w - c_elem.slider.handle.w);
|
||||||
float v = (float)(c_elem.slider.handle.x-c_elem.bounds.x) / (float)(c_elem.bounds.w-c_elem.slider.handle.w);
|
float v = (float)(c_elem.slider.handle.x-c_elem.bounds.x) / (float)(c_elem.bounds.w-c_elem.slider.handle.w);
|
||||||
c_elem.slider.handle.x = x;
|
c_elem.slider.handle.x = x;
|
||||||
@ -89,7 +89,7 @@ fn ElemEvents! Ctx.slider_ver(&ctx, String label, Rect size)
|
|||||||
|
|
||||||
c_elem.events = ctx.get_elem_events(c_elem);
|
c_elem.events = ctx.get_elem_events(c_elem);
|
||||||
if (parent.flags.has_focus && c_elem.events.mouse_hover) {
|
if (parent.flags.has_focus && c_elem.events.mouse_hover) {
|
||||||
if (point_in_rect(ctx.input.mouse.pos, c_elem.slider.handle) && c_elem.events.mouse_hold) {
|
if (point_in_rect(ctx.input.mouse.pos, c_elem.slider.handle) && c_elem.events.mouse_hold) {
|
||||||
short y = (short)clamp(ctx.input.mouse.pos.y - c_elem.slider.handle.h/2, c_elem.bounds.y, c_elem.bounds.y + c_elem.bounds.h - c_elem.slider.handle.h);
|
short y = (short)clamp(ctx.input.mouse.pos.y - c_elem.slider.handle.h/2, c_elem.bounds.y, c_elem.bounds.y + c_elem.bounds.h - c_elem.slider.handle.h);
|
||||||
float v = (float)(c_elem.slider.handle.y-c_elem.bounds.y) / (float)(c_elem.bounds.h-c_elem.slider.handle.h);
|
float v = (float)(c_elem.slider.handle.y-c_elem.bounds.y) / (float)(c_elem.bounds.h-c_elem.slider.handle.h);
|
||||||
c_elem.slider.handle.y = y;
|
c_elem.slider.handle.y = y;
|
||||||
|
@ -62,7 +62,7 @@ fn void! Ctx.text_unbounded(&ctx, String label, String text)
|
|||||||
|
|
||||||
// 1. Fill the element fields
|
// 1. Fill the element fields
|
||||||
// this resets the flags
|
// this resets the flags
|
||||||
c_elem.type = ETYPE_TEXT;
|
c_elem.type = ETYPE_TEXT;
|
||||||
|
|
||||||
short baseline = (short)ctx.font.ascender;
|
short baseline = (short)ctx.font.ascender;
|
||||||
short line_height = (short)ctx.font.ascender - (short)ctx.font.descender;
|
short line_height = (short)ctx.font.ascender - (short)ctx.font.descender;
|
||||||
|
30
src/vtree.c3
30
src/vtree.c3
@ -10,11 +10,11 @@ struct VTree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fault VTreeError {
|
fault VTreeError {
|
||||||
CANNOT_SHRINK,
|
CANNOT_SHRINK,
|
||||||
INVALID_REFERENCE,
|
INVALID_REFERENCE,
|
||||||
TREE_FULL,
|
TREE_FULL,
|
||||||
REFERENCE_NOT_PRESENT,
|
REFERENCE_NOT_PRESENT,
|
||||||
INVALID_ARGUMENT,
|
INVALID_ARGUMENT,
|
||||||
}
|
}
|
||||||
|
|
||||||
macro VTree.ref_is_valid(&tree, isz ref) { return (ref >= 0 && ref < tree.refs.len); }
|
macro VTree.ref_is_valid(&tree, isz ref) { return (ref >= 0 && ref < tree.refs.len); }
|
||||||
@ -116,8 +116,8 @@ fn void! VTree.resize(&tree, usz newsize)
|
|||||||
defer catch { (void)mem::free(tree.ordered_refs); }
|
defer catch { (void)mem::free(tree.ordered_refs); }
|
||||||
|
|
||||||
if (newsize > tree.size()) {
|
if (newsize > tree.size()) {
|
||||||
tree.vector[old_size..newsize-1] = @zero();
|
tree.vector[old_size..newsize-1] = @zero();
|
||||||
tree.refs[old_size..newsize-1] = -1;
|
tree.refs[old_size..newsize-1] = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,13 +131,13 @@ fn isz! VTree.add(&tree, ElemType elem, isz parent)
|
|||||||
|
|
||||||
// no space left
|
// no space left
|
||||||
if (tree.elements >= tree.size()) {
|
if (tree.elements >= tree.size()) {
|
||||||
return VTreeError.TREE_FULL?;
|
return VTreeError.TREE_FULL?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the parent exists
|
// check if the parent exists
|
||||||
// if there are no elements in the tree the first add will set the root
|
// if there are no elements in the tree the first add will set the root
|
||||||
if (!tree.ref_is_present(parent) && tree.elements != 0) {
|
if (!tree.ref_is_present(parent) && tree.elements != 0) {
|
||||||
return VTreeError.REFERENCE_NOT_PRESENT?;
|
return VTreeError.REFERENCE_NOT_PRESENT?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the first free spot
|
// get the first free spot
|
||||||
@ -164,7 +164,7 @@ fn isz! VTree.add(&tree, ElemType elem, isz parent)
|
|||||||
// returns the number of pruned elements
|
// returns the number of pruned elements
|
||||||
fn usz! VTree.prune(&tree, isz ref)
|
fn usz! VTree.prune(&tree, isz ref)
|
||||||
{
|
{
|
||||||
if (!tree.ref_is_valid(ref)) {
|
if (!tree.ref_is_valid(ref)) {
|
||||||
return VTreeError.INVALID_REFERENCE?;
|
return VTreeError.INVALID_REFERENCE?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ fn usz! VTree.prune(&tree, isz ref)
|
|||||||
// find the size of the subtree starting from ref
|
// find the size of the subtree starting from ref
|
||||||
fn usz! VTree.subtree_size(&tree, isz ref)
|
fn usz! VTree.subtree_size(&tree, isz ref)
|
||||||
{
|
{
|
||||||
if (!tree.ref_is_valid(ref)) {
|
if (!tree.ref_is_valid(ref)) {
|
||||||
return VTreeError.INVALID_REFERENCE?;
|
return VTreeError.INVALID_REFERENCE?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ fn isz! VTree.children_it(&tree, isz parent, isz *cursor)
|
|||||||
fn isz! VTree.level_order_it(&tree, isz ref, isz *cursor)
|
fn isz! VTree.level_order_it(&tree, isz ref, isz *cursor)
|
||||||
{
|
{
|
||||||
if (cursor == null) {
|
if (cursor == null) {
|
||||||
return VTreeError.INVALID_ARGUMENT?;
|
return VTreeError.INVALID_ARGUMENT?;
|
||||||
}
|
}
|
||||||
|
|
||||||
isz[] queue = tree.ordered_refs;
|
isz[] queue = tree.ordered_refs;
|
||||||
@ -301,7 +301,7 @@ fn isz! VTree.parentof(&tree, isz ref)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!tree.ref_is_present(ref)) {
|
if (!tree.ref_is_present(ref)) {
|
||||||
return VTreeError.REFERENCE_NOT_PRESENT?;
|
return VTreeError.REFERENCE_NOT_PRESENT?;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tree.refs[ref];
|
return tree.refs[ref];
|
||||||
@ -309,12 +309,12 @@ fn isz! VTree.parentof(&tree, isz ref)
|
|||||||
|
|
||||||
fn ElemType! VTree.get(&tree, isz ref)
|
fn ElemType! VTree.get(&tree, isz ref)
|
||||||
{
|
{
|
||||||
if (!tree.ref_is_valid(ref)) {
|
if (!tree.ref_is_valid(ref)) {
|
||||||
return VTreeError.INVALID_REFERENCE?;
|
return VTreeError.INVALID_REFERENCE?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tree.ref_is_present(ref)) {
|
if (!tree.ref_is_present(ref)) {
|
||||||
return VTreeError.REFERENCE_NOT_PRESENT?;
|
return VTreeError.REFERENCE_NOT_PRESENT?;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tree.vector[ref];
|
return tree.vector[ref];
|
||||||
|
Loading…
Reference in New Issue
Block a user