another problem with hashtables 
Author Message
 another problem with hashtables

Hello,

I'm making an indexing mechanism for knowledge systems.
it can store facts in a hashtable of hashtables.

eg, if you have the fact (is-brother tom john)
it first creates an hashtable with key "is brother" (if it doesn't exist)
after this it creates a sub-hash of "is brother" with the relations.
in this example it adds the list (tom john) to it. I use as key also (tom
john)

But now when i search for (tom john) in the table, it gives a false.

I wrote a very simple code to show the problem:

-------------------------------

(define (key-in-hash-table-exists? hash-table key-v)
  (if (hash-table-get hash-table key-v (lambda () #f))
    #t
    #f))

(define x (make-hash-table))
(hash-table-put! x '(abc cd) '(abc cd))
(key-in-hash-table-exists? x '(abc cd))  ;--> i expected #t, it returns a
false

-------------------------------

How to fix this problem?

tnx,
Stijn



Tue, 27 Sep 2005 22:24:33 GMT  
 another problem with hashtables

Quote:
> I wrote a very simple code to show the problem:

> -------------------------------

> (define (key-in-hash-table-exists? hash-table key-v)
>   (if (hash-table-get hash-table key-v (lambda () #f))
>     #t
>     #f))

> (define x (make-hash-table))
> (hash-table-put! x '(abc cd) '(abc cd))
> (key-in-hash-table-exists? x '(abc cd))  ;--> i expected #t, it returns a
> false

> -------------------------------

> How to fix this problem?

Use:

    (define x (make-hash-table 'equal))

From the PLT Scheme docs at:
http://download.plt-scheme.org/doc/203/html/mzscheme/mzscheme-Z-H-3.h...
ec_3.12 :

    'equal -- creates a hash table that compares keys using equal?
    instead of eq? (needed, for example, when using strings as keys).

You're using lists as keys.  (eq? '(abc cd) '(abc cd)) is #f.

Anton



Tue, 27 Sep 2005 23:18:10 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. String HashTables

2. Hashtables in Lisp

3. weak hashtables in LW 4.2

4. string or int hashtables

5. Problems, problems, problems

6. Eiffel Problems, Problems, Problems

7. Finn Idiom problems and Re: {rho} problem

8. Combinatorial Problem [ & a new Combinatorial Problem ]

9. Database problem/Memory problem??

10. CW 2003 - Focus problem & a select problem

11. 32bit problem - one problem solved & another found

12. GForth problem or my problem?

 

 
Powered by phpBB® Forum Software