use builtin hash functions instead of rolling my own
This commit is contained in:
parent
bb1745a05d
commit
9a785e0f06
@ -5,7 +5,7 @@ import std::io;
|
|||||||
// draw a button, return the events on that button
|
// draw a button, return the events on that button
|
||||||
fn ElemEvents! Ctx.button(&ctx, String label, Rect size)
|
fn ElemEvents! Ctx.button(&ctx, String label, Rect size)
|
||||||
{
|
{
|
||||||
Id id = hash(label);
|
Id id = label.hash();
|
||||||
|
|
||||||
Elem *parent = ctx.get_parent()!;
|
Elem *parent = ctx.get_parent()!;
|
||||||
Elem *c_elem = ctx.get_elem(id)!;
|
Elem *c_elem = ctx.get_elem(id)!;
|
||||||
|
@ -104,22 +104,6 @@ fault UgError {
|
|||||||
UNEXPECTED_ELEMENT,
|
UNEXPECTED_ELEMENT,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn Id fnv1a(String str)
|
|
||||||
{
|
|
||||||
const ulong FNV_OFF = 0xcbf29ce484222325;
|
|
||||||
const ulong FNV_PRIME = 0x100000001b3;
|
|
||||||
|
|
||||||
ulong hash = FNV_OFF;
|
|
||||||
foreach (c : str) {
|
|
||||||
hash ^= c;
|
|
||||||
hash *= FNV_PRIME;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
macro hash(String str) { return fnv1a(str); }
|
|
||||||
|
|
||||||
macro uint_to_rgba(uint u) {
|
macro uint_to_rgba(uint u) {
|
||||||
return Color{
|
return Color{
|
||||||
.r = (char)((u >> 24) & 0xff),
|
.r = (char)((u >> 24) & 0xff),
|
||||||
|
@ -4,7 +4,7 @@ import std::io;
|
|||||||
|
|
||||||
fn void! Ctx.div_begin(&ctx, String label, Rect size)
|
fn void! Ctx.div_begin(&ctx, String label, Rect size)
|
||||||
{
|
{
|
||||||
Id id = hash(label);
|
Id id = label.hash();
|
||||||
|
|
||||||
Elem *parent = ctx.get_parent()!;
|
Elem *parent = ctx.get_parent()!;
|
||||||
Elem* c_elem = ctx.get_elem(id)!;
|
Elem* c_elem = ctx.get_elem(id)!;
|
||||||
|
@ -28,7 +28,7 @@ macro Ctx.get_elem(&ctx, Id id)
|
|||||||
// if it does't find one
|
// if it does't find one
|
||||||
macro Ctx.get_elem_by_label(&ctx, String label)
|
macro Ctx.get_elem_by_label(&ctx, String label)
|
||||||
{
|
{
|
||||||
Id id = hash(label);
|
Id id = label.hash();
|
||||||
return ctx.cache.search(id);
|
return ctx.cache.search(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import std::io;
|
|||||||
*/
|
*/
|
||||||
fn ElemEvents! Ctx.slider_hor(&ctx, String label, Rect size)
|
fn ElemEvents! Ctx.slider_hor(&ctx, String label, Rect size)
|
||||||
{
|
{
|
||||||
Id id = hash(label);
|
Id id = label.hash();
|
||||||
|
|
||||||
Elem *parent = ctx.get_parent()!;
|
Elem *parent = ctx.get_parent()!;
|
||||||
Elem *c_elem = ctx.get_elem(id)!;
|
Elem *c_elem = ctx.get_elem(id)!;
|
||||||
@ -81,7 +81,7 @@ fn ElemEvents! Ctx.slider_hor(&ctx, String label, Rect size)
|
|||||||
*/
|
*/
|
||||||
fn ElemEvents! Ctx.slider_ver(&ctx, String label, Rect size)
|
fn ElemEvents! Ctx.slider_ver(&ctx, String label, Rect size)
|
||||||
{
|
{
|
||||||
Id id = hash(label);
|
Id id = label.hash();
|
||||||
|
|
||||||
Elem *parent = ctx.get_parent()!;
|
Elem *parent = ctx.get_parent()!;
|
||||||
Elem *c_elem = ctx.get_elem(id)!;
|
Elem *c_elem = ctx.get_elem(id)!;
|
||||||
|
Loading…
Reference in New Issue
Block a user