changeset 1095:2443152dc2f1

add Luan.hash_code() and Table.hash_value()
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 21 Feb 2017 20:27:17 -0700
parents cb4c20fce7d0
children 5dc601c4ed6d
files src/luan/LuanTable.java src/luan/modules/BasicLuan.java src/luan/modules/Luan.luan src/luan/modules/Table.luan src/luan/modules/TableLuan.java
diffstat 5 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/LuanTable.java	Tue Jan 24 14:14:43 2017 -0700
+++ b/src/luan/LuanTable.java	Tue Feb 21 20:27:17 2017 -0700
@@ -469,4 +469,12 @@
 		list = null;
 	}
 
+	public int hashValue() {
+		int n = 99;
+		if( map != null )
+			n ^= map.hashCode();
+		if( list != null )
+			n ^= list.hashCode();
+		return n;
+	}
 }
--- a/src/luan/modules/BasicLuan.java	Tue Jan 24 14:14:43 2017 -0700
+++ b/src/luan/modules/BasicLuan.java	Tue Feb 21 20:27:17 2017 -0700
@@ -240,4 +240,12 @@
 		return v.getClass().getSimpleName().toLowerCase();
 	}
 
+	public static int hash_code(Object obj) throws LuanException {
+		if( obj == null ) {
+			return 0;
+		} else {
+			return obj.hashCode();
+		}
+	}
+
 }
--- a/src/luan/modules/Luan.luan	Tue Jan 24 14:14:43 2017 -0700
+++ b/src/luan/modules/Luan.luan	Tue Feb 21 20:27:17 2017 -0700
@@ -12,6 +12,7 @@
 Luan.assert_string = BasicLuan.assert_string
 Luan.assert_table = BasicLuan.assert_table
 Luan.get_metatable = BasicLuan.get_metatable
+Luan.hash_code = BasicLuan.hash_code
 Luan.ipairs = BasicLuan.ipairs
 Luan.load = BasicLuan.load
 Luan.load_file = BasicLuan.load_file
--- a/src/luan/modules/Table.luan	Tue Jan 24 14:14:43 2017 -0700
+++ b/src/luan/modules/Table.luan	Tue Feb 21 20:27:17 2017 -0700
@@ -6,6 +6,7 @@
 Table.clear = TableLuan.clear
 Table.concat = TableLuan.concat
 Table.copy = TableLuan.copy
+Table.hash_value = TableLuan.hash_value
 Table.insert = TableLuan.insert
 Table.pack = TableLuan.pack
 Table.remove = TableLuan.remove
--- a/src/luan/modules/TableLuan.java	Tue Jan 24 14:14:43 2017 -0700
+++ b/src/luan/modules/TableLuan.java	Tue Feb 21 20:27:17 2017 -0700
@@ -112,4 +112,8 @@
 		tbl.rawClear();
 	}
 
+	public static int hash_value(LuanTable tbl) throws LuanException {
+		return tbl.hashValue();
+	}
+
 }