diff options
| author | Cliff Click <cliffc@acm.org> | 2026-09-29 12:34:58 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-09-29 12:34:58 -0700 |
| commit | 502e7e752f3efdb069a36b23ab51ac22f9d74e9e (patch) | |
| tree | d2b3c84357be365b5a6cc674285d1d2778c0072c /src/main/java/com/seaofnodes/simple/Utils.java | |
| parent | fdfc4e4b824e97952110069558de70cd16c725a1 (diff) | |
| download | Simple-linear-chapter10a.tar.gz Simple-linear-chapter10a.zip | |
Chapter 10a: Structs and Memorylinear-chapter10a
Diffstat (limited to 'src/main/java/com/seaofnodes/simple/Utils.java')
| -rw-r--r-- | src/main/java/com/seaofnodes/simple/Utils.java | 26 |
1 files changed, 26 insertions, 0 deletions
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 <E> int find( E[] ary, E x ) { + for( int i=0; i<ary.length; i++ ) + if( ary[i]==x ) + return i; + return -1; + } + + // Rotate a long, nice for hashes + public static long rot( long x, int n ) { return (x<<n) | (x>>>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; + } } |
