Serge D. Mechveliani wrote:
> 
> On Sat, Mar 17, 2012 at 07:11:30PM +0100, Ralf Hemmecke wrote:
> > https://github.com/hemmecke/fricas-svn/blob/master/src/algebra/table.spad.pamphlet
> 
> Yes, I am looking into                   HasTable(Key, Entry, hashfn),
> and even managed to use an example with  HasTable(INT, String, "ID").
> 
> -------------------------------------------------------
> INT  ==> Integer
> Item ==> Record(key : INT, entry : String)
> Tab  ==> HashTable(INT, String, "ID")
> 
> )abbrev package FOO Foo
> Foo() : with
>         tab : () -> Tab
>  ==
>   add
>     tab() ==
>           item1    := [1, "1"] :: Item
>           item2    := [2, "2"] :: Item
>                   itemList : List Item := [item1, item2]
>           construct(itemList) $Tab
> -------------------------------------------------------
> 
> (11) -> tab1:= tab()
>    (11)  table(2= "2",1= "1")           Type: HashTable(Integer,String,ID)
> 
> (12) -> search(2, tab1)
>    (12)  "2"                            Type: Union(String,...)
> 
> 
> Does "ID" mean to compare the keys as they are?
> Will this be a binary search?
> Key  is declared of  SetCategory.
> And the binary search requires a total ordering on Key, which, I think,
> is beyond SetCategory (?)
> May be, this is some internally used ordering, I do not know ...
> How to set  hashfn  is a bit unclear:  "ID", "EQ" ...
> So far, I am trying "ID" and hope for the binary search.
> 

This is _hash_ table, no order is required.  Currently valid
hashfn are EQ, ID, CVEC, EQL, UEQUAL, and EQUAL.  EQ and ID
are the same and they check if arguments are the same thing
(that is two different strings consisting if the same
characters compare as non equal).  EQL is good for numbers.
CVEC, UEQUAL and EQUAL means the same and compare objects
look the same.  Normally you want EQUAL.

Actually, FriCAS HashTable domain is a tiny wrapper over
Lisp hash tables and semantics is directly taken from
Lisp.  In practice this means that unless you are using one
of small set of domains the results will be incorrect,
in the sense that hash table uses its own notion of
equality.

Note that FriCAS has a Table domain, which automatically will
use HashTable if that works and otherwise use linear search
on lists (IIUC you want to avoid this).

-- 
                              Waldek Hebisch
[email protected] 

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/fricas-devel?hl=en.

Reply via email to