From 502e7e752f3efdb069a36b23ab51ac22f9d74e9e Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Tue, 29 Sep 2026 12:34:58 -0700 Subject: Chapter 10a: Structs and Memory --- src/main/java/com/seaofnodes/simple/Utils.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/main/java/com/seaofnodes/simple/Utils.java') diff --git a/src/main/java/com/seaofnodes/simple/Utils.java b/src/main/java/com/seaofnodes/simple/Utils.java index 45f15327..4f2af769 100644 --- a/src/main/java/com/seaofnodes/simple/Utils.java +++ b/src/main/java/com/seaofnodes/simple/Utils.java @@ -36,4 +36,30 @@ public class Utils { return i; return -1; } + /** + * Search a list for an element by reference + * + * @param ary List to search in + * @param x Object to be searched + * @return >= 0 on success, -1 on failure + */ + public static int find( E[] ary, E x ) { + for( int i=0; i>>n); } + + // Fold a 64bit hash into 32 bits + public static int fold( long x ) { return (int)((x>>32) ^ x); } + + public static boolean eq(String s0, String s1) { + if( s0==s1 ) return true; + assert s0==s0.intern(); + assert s1==s1.intern(); + return false; + } } -- cgit v1.2.3