Changeset 5998


Ignore:
Timestamp:
02/27/04 02:24:12 (17 years ago)
Author:
piso
Message:

hash(), GETHASH

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/HashTable.java

    r5774 r5998  
    33 *
    44 * Copyright (C) 2002-2004 Peter Graves
    5  * $Id: HashTable.java,v 1.32 2004-02-12 01:56:27 piso Exp $
     5 * $Id: HashTable.java,v 1.33 2004-02-27 02:24:12 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    210210    }
    211211
    212     final int hash(LispObject key) throws ConditionThrowable
    213     {
    214         return key == null ? 0 : (key.sxhash().getValue() % buckets.length);
     212    private final int hash(LispObject key) throws ConditionThrowable
     213    {
     214        return key == null ? 0 : (key.sxhash().value % buckets.length);
    215215    }
    216216
     
    300300    // ### gethash
    301301    // gethash key hash-table &optional default => value, present-p
    302     private static final Primitive GETHASH = new Primitive("gethash","key hash-table &optional default") {
    303         public LispObject execute(LispObject[] args) throws ConditionThrowable
    304         {
    305             final int length = args.length;
    306             if (length < 2 || length > 3)
    307                 return signal(new WrongNumberOfArgumentsException(this));
    308             if (args[1] instanceof HashTable) {
    309                 LispObject key = args[0];
    310                 HashTable ht = (HashTable) args[1];
    311                 LispObject defaultValue =
    312                     length == 3 ? args[2] : NIL;
    313                 return ht.gethash(key, defaultValue);
    314             }
    315             return signal(new TypeError(args[1], "hash-table"));
     302    private static final Primitive GETHASH =
     303        new Primitive("gethash","key hash-table &optional default")
     304    {
     305        public LispObject execute(LispObject first, LispObject second)
     306            throws ConditionThrowable
     307        {
     308            try {
     309                return ((HashTable)second).gethash(first, NIL);
     310            }
     311            catch (ClassCastException e) {
     312                return signal(new TypeError(second, Symbol.HASH_TABLE));
     313            }
     314        }
     315        public LispObject execute(LispObject first, LispObject second,
     316                                  LispObject third)
     317            throws ConditionThrowable
     318        {
     319            try {
     320                return ((HashTable)second).gethash(first, third);
     321            }
     322            catch (ClassCastException e) {
     323                return signal(new TypeError(second, Symbol.HASH_TABLE));
     324            }
    316325        }
    317326    };
Note: See TracChangeset for help on using the changeset viewer.