cleanup: removed old references to `to_u32`
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 15 Mar 2023 01:24:50 +0000 (20:24 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 15 Mar 2023 01:24:50 +0000 (20:24 -0500)
core/container/map.onyx
core/container/optional.onyx
core/container/pair.onyx
core/container/result.onyx
core/container/set.onyx
core/hash/hash.onyx

index b8d4c0293c5705c901edbe70e236a03143108087..d0425540e0e5fb734b2ac333ef4e9845bcae0d25 100644 (file)
@@ -6,7 +6,7 @@ use core.intrinsics.onyx { __initialize }
 //
 // Map is a generic hash-map implementation that uses chaining.
 // Values can be of any type. Keys must of a type that supports
-// the core.hash.to_u32, and the '==' operator.
+// the core.hash.hash, and the '==' operator.
 //
 @conv.Custom_Format.{ #solidify format_map {K=Key_Type, V=Value_Type} }
 Map :: struct (Key_Type: type_expr, Value_Type: type_expr) where ValidKey(Key_Type) {
@@ -28,11 +28,11 @@ Map :: struct (Key_Type: type_expr, Value_Type: type_expr) where ValidKey(Key_Ty
 
 #local ValidKey :: interface (t: $T) {
     // In order to use a certain type as a key in a Map, you must
-    // provide an implementation of core.hash.to_u32() for that type,
+    // provide an implementation of core.hash.hash() for that type,
     // and you must provide an operator overload for ==.
 
-    { hash.to_u32(t) } -> u32;
-    { t == t         } -> bool;
+    { hash.hash(t) } -> u32;
+    { t == t       } -> bool;
 }
 
 #inject Map {
@@ -312,7 +312,7 @@ as_iter :: (m: &Map) =>
         if hashes.data == null do init(map);
         lr := MapLookupResult.{};
 
-        hash_value: u32 = hash.to_u32(key);
+        hash_value: u32 = hash.hash(key);
         lr.hash = hash_value;
 
         lr.hash_index = hash_value % hashes.count;
index e4d961a3cbda5aa61bd5e03ba4406f1ca3a0f189..d6d773e3d96613d2325169661d7fa6cc29fc84eb 100644 (file)
@@ -97,7 +97,7 @@ package core
 
     hash :: (o: ?$T/core.hash.Hashable) -> u32 {
         if !o.has_value do return 0;
-        return core.hash.to_u32(o.value);
+        return core.hash.hash(o.value);
     }
 }
 
index 3a464535e3617908cfcc898cb979fe4651d2d759..d91bc18a06eb6335c9b5555c093cbcfc9ae95dfd 100644 (file)
@@ -24,10 +24,10 @@ Pair :: struct (First_Type: type_expr, Second_Type: type_expr) {
 }
 
 #overload
-core.hash.to_u32 :: (p: Pair($First_Type/hash.Hashable, $Second_Type/hash.Hashable)) => {
+core.hash.hash :: (p: Pair($First_Type/hash.Hashable, $Second_Type/hash.Hashable)) => {
     h := 7;
-    h += h << 5 + hash.to_u32(p.first);
-    h += h << 5 + hash.to_u32(p.second);
+    h += h << 5 + hash.hash(p.first);
+    h += h << 5 + hash.hash(p.second);
     return h;
 }
 
index 4e0ce7cc3a2dc200cd31fc4897e54b01c6ffa79c..23fc812ab87d854f22e1be05e69e1e7fa6b6983b 100644 (file)
@@ -182,3 +182,10 @@ Result_Data :: struct (T: type_expr, E: type_expr) {
 #overload
 __implicit_bool_cast :: macro (r: Result($O, $E)) => r.status == .Ok;
 
+
+#operator ? macro (r: Result($T, $E)) -> T {
+    res := r;
+    if r.status == .Ok do return r.__data.value;
+
+    return return .{ .Err, .{ error = res.__data.error } };
+}
index e38ef8919c06ecbb9343af38a4b3657e821d56f9..29bc7aa2d22e68eeeaa4ea5bed0ac657b416c10c 100644 (file)
@@ -3,7 +3,7 @@ package core.set
 use core {array, hash, memory, math, Optional}
 
 #local SetValue :: interface (t: $T) {
-    { hash.to_u32(t) } -> u32;
+    { hash.hash(t) } -> u32;
     { t == t } -> bool;
 }
 
@@ -155,7 +155,7 @@ as_iter :: (s: &Set) =>
     lookup :: (use set: &Set, value: set.Elem_Type) -> SetLookupResult {
         lr := SetLookupResult.{};
 
-        hash_value: u32 = hash.to_u32(value); // You cannot have a set of this type without defining a to_u32 hash.
+        hash_value: u32 = hash.hash(value); // You cannot have a set of this type without defining a hash function.
         lr.hash = hash_value;
 
         lr.hash_index = hash_value % hashes.count;
index 739a79b2acc90cf829852bba1eaa4fbbada36741..b3345d506ade10266af118b5a8cbc2d76eedf80c 100644 (file)
@@ -37,7 +37,7 @@ hash :: #match -> u32 {
         for ch: key do hash += (hash << 5) + ~~ch;
         return hash;
     },
-    (key: type_expr) -> u32 { return to_u32(cast(u32) key); },
+    (key: type_expr) -> u32 { return hash(cast(u32) key); },
     (key: bool)   -> u32 { return 1 if key else 0; },
 
     #order 10000