SYS:HASH-TABLE-WEAKNESS provides the weakness property of a hashtable.

parent bd90e2da
......@@ -412,6 +412,27 @@ public final class HashTableFunctions
}
};
@DocString(name="hash-table-weakness",
args="hash-table",
doc="Return weakness property of HASH-TABLE, or NIL if it has none.")
private static final Primitive HASH_TABLE_WEAKNESS
= new pf_hash_table_weakness();
private static final class pf_hash_table_weakness extends Primitive {
pf_hash_table_weakness() {
super(Symbol.HASH_TABLE_WEAKNESS, "hash-table");
}
@Override
public LispObject execute(LispObject first)
{
if (first instanceof HashTable) {
return NIL;
} else if (first instanceof WeakHashTable) {
return ((WeakHashTable)first).getWeakness();
}
return error(new TypeError(first, Symbol.HASH_TABLE));
}
};
protected static HashTable checkHashTable(LispObject ht) {
if (ht instanceof HashTable) return (HashTable)ht;
type_error(ht, Symbol.HASH_TABLE);
......
......@@ -3045,6 +3045,8 @@ public class Symbol extends LispObject implements java.io.Serializable
PACKAGE_SYS.addExternalSymbol("GETHASH1");
public static final Symbol PUTHASH =
PACKAGE_SYS.addExternalSymbol("PUTHASH");
public static final Symbol HASH_TABLE_WEAKNESS =
PACKAGE_SYS.addExternalSymbol("HASH-TABLE-WEAKNESS");
public static final Symbol UNDEFINED_FUNCTION_CALLED =
PACKAGE_SYS.addExternalSymbol("UNDEFINED-FUNCTION-CALLED");
public static final Symbol SET_CHAR =
......
......@@ -45,10 +45,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
// ??? Replace standard Hashtable when this code is working; maybe not
// because we have additional places for locking here.
//
......@@ -78,6 +74,7 @@ public class WeakHashTable
final Comparator comparator;
final private ReentrantLock lock = new ReentrantLock();
HashEntry bucketType;
final LispObject weakness;
private WeakHashTable(Comparator c, int size, LispObject rehashSize,
LispObject rehashThreshold, LispObject weakness)
......@@ -85,6 +82,7 @@ public class WeakHashTable
this.rehashSize = rehashSize;
this.rehashThreshold = rehashThreshold;
bucketType = null;
this.weakness = weakness;
if (weakness.equals(Keyword.KEY)) {
bucketType = this.new HashEntryWeakKey();
} else if (weakness.equals(Keyword.VALUE)) {
......@@ -350,6 +348,10 @@ public class WeakHashTable
public Symbol getTest() {
return comparator.getTest();
}
public LispObject getWeakness() {
return weakness;
}
HashEntry[] getTable() {
lock.lock();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment