[GiNaC-list] hash tables and sets
Marko Riedel
mriedel at lsi.upc.edu
Tue Oct 10 13:19:54 CEST 2006
Chris Dams writes:
>
> Dear Marko,
>
> On Mon, 18 Sep 2006, Marko Riedel wrote:
>
> > 1. What C++ type is best suited to representing sets?
>
> There is a class set defined in the standard library. I would go for that
> unless there is a good reason you cannot use it. You should use
>
> > 2. Is there a hash function implemented for GiNaC expressions?
>
> Yes there is. Call the method
>
> unsigned ex::gethash()
>
> to obtain the hash value. You should use std::set<ex, ex_is_less>.
>
Hi again,
I have another very basic question. Suppose I have an ordinary C
structure (I will use C in my example, rather than Objective C, to
keep it simple) containing some fields e.g.
typedef struct {
int a, b;
char *name;
} mystruct;
Now I want to add a field to it (at compile time, of course),
containing a set of expressions, using std::set<ex, ex_is_less>, as
you suggested. How would I declare this field? What headers do I need
to import?
Furthermore I have two functions, "make_instance" and "free_instance."
The function "make_instance" calls "malloc" to allocate the structure,
as in
inst = (mystruct *)malloc(sizeof(mystruct));
inst->a = inst->b = 0;
inst->name = NULL;
What do I have to do to allocate and initialize a new set of
expressions, e.g. what goes on the right side of
inst->set = /* ??? */
The function "free_instance" frees the name field, the set, and the
structure itself, as in
if(inst->name!=NULL){ free(inst->name); }
/* free inst->set */
free(inst);
What do I need to put on the second line (the one that frees the set).
Thank you for your patience with these extremely basic questions. I
belong to the class of users that are not familiar with C++ but want
to use GiNaC just the same.
Best regards,
Marko Riedel
+-------------------------------------------------------------+
| Marko Riedel, EDV Neue Arbeit gGmbH, mriedel at lsi.upc.edu |
| http://www.geocities.com/markoriedelde/index.html |
+-------------------------------------------------------------+
More information about the GiNaC-list
mailing list