My Project
Loading...
Searching...
No Matches
Functions
htable.cc File Reference
#include "kernel/mod2.h"
#include "resources/hash_me.h"
#include "reporter/reporter.h"
#include "Singular/htable.h"

Go to the source code of this file.

Functions

stablerect_createTable (int s)
 
void t_destroyTable (stablerec *t)
 
stablereccopyTable (stablerec *t)
 
charstringTable (stablerec *t)
 
telem t_findTable (stablerec *t, const char *s)
 find the entry to key s
 
leftv t_findTabelVal (stablerec *t, const char *s)
 find the data to key s
 
void t_addTable (stablerec *t, char *s, leftv v)
 add a new entry (key s, data v) to table t, eats s, copies v
 
void htable_Print (stablerec *d)
 

Function Documentation

◆ copyTable()

stablerec * copyTable ( stablerec t)

Definition at line 42 of file htable.cc.

43{
44 t->ref++;
45 return t;
46}
int ref
Definition htable.h:26

◆ htable_Print()

void htable_Print ( stablerec d)

Definition at line 108 of file htable.cc.

109{
110 stablerec* lt=(stablerec*)d;
111 char* s=stringTable(lt);
112 PrintS(s);
113 omFree(s);
114 int cnt=0;int cnt2=0;
115 for(int i=0;i<lt->max;i++)
116 {
117 if (lt->t[i]!=NULL)
118 {
119 cnt++;
120 telem p=lt->t[i];
121 while(p!=NULL) { cnt2++;p=p->next;}
122 }
123 }
124 Print("%d columns, %d entries, size:%d",cnt,cnt2,lt->max);
125}
int i
Definition cfEzgcd.cc:132
int p
Definition cfModGcd.cc:4086
#define Print
Definition emacs.cc:80
const CanonicalForm int s
Definition facAbsFact.cc:51
char * stringTable(stablerec *t)
Definition htable.cc:48
telem * t
Definition htable.h:24
int max
Definition htable.h:25
#define omFree(addr)
#define NULL
Definition omList.c:12
void PrintS(const char *s)
Definition reporter.cc:288

◆ stringTable()

char * stringTable ( stablerec t)

Definition at line 48 of file htable.cc.

49{
50 StringSetS("table:\n");
51 char *s;
52 for(int i=t->max-1;i>=0;i--)
53 {
54 telem p=t->t[i];
55 while(p!=NULL)
56 {
57 StringAppendS(p->key);
58 StringAppendS(" -> ");
59 s=p->val.String();
61 omFree(s);
62 StringAppendS("\n");
63 telem pp=p;
64 p=p->next;
65 }
66 }
67 return StringEndS();
68}
CanonicalForm FACTORY_PUBLIC pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition cf_gcd.cc:676
void StringSetS(const char *st)
Definition reporter.cc:128
void StringAppendS(const char *st)
Definition reporter.cc:107
char * StringEndS()
Definition reporter.cc:151

◆ t_addTable()

void t_addTable ( stablerec t,
char s,
leftv  v 
)

add a new entry (key s, data v) to table t, eats s, copies v

add a new entry (key s, data v) to table t

Definition at line 93 of file htable.cc.

94{
96 telem p=(telem)omAlloc(sizeof(*p));
97 p->next=NULL;
98 p->key=s;
99 p->val.Init();
100 p->val.rtyp=v->Typ();
101 p->val.data=v->CopyD();
102 p->hash=h;
103 h=h%t->max;
104 p->next=t->t[h];
105 t->t[h]=p;
106}
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
uint32_t hashlittle(const void *key, size_t length)
Definition hash_me.c:68
STATIC_VAR Poly * h
Definition janet.cc:971
#define omAlloc(size)

◆ t_createTable()

stablerec * t_createTable ( int  s)

Definition at line 11 of file htable.cc.

12{
14 t->max=s;
15 t->t=(telem*)omAlloc0(s*sizeof(telem));
16 t->ref=1;
17 return t;
18}
#define omAlloc0(size)

◆ t_destroyTable()

void t_destroyTable ( stablerec t)

Definition at line 20 of file htable.cc.

21{
22 t->ref--;
23 if (t->ref<=0)
24 {
25 for(int i=t->max-1;i>=0;i--)
26 {
27 telem p=t->t[i];
28 while(p!=NULL)
29 {
30 omFree(p->key);
31 p->val.CleanUp();
32 telem pp=p;
33 p=p->next;
34 omFreeSize(pp,sizeof(stelem));
35 }
36 }
37 omFreeSize(t->t,t->max*sizeof(telem));
38 omFreeSize(t,sizeof(stablerec));
39 }
40}
#define omFreeSize(addr, size)

◆ t_findTabelVal()

leftv t_findTabelVal ( stablerec t,
const char s 
)

find the data to key s

Definition at line 85 of file htable.cc.

86{
88 if (p==NULL) return NULL;
89 return &(p->val);
90}
telem t_findTable(stablerec *t, const char *s)
find the entry to key s
Definition htable.cc:71

◆ t_findTable()

telem t_findTable ( stablerec t,
const char s 
)

find the entry to key s

Definition at line 71 of file htable.cc.

72{
74 h=h%t->max;
75 telem p=t->t[h];
76 while(p!=NULL)
77 {
78 if (strcmp(s,p->key)==0) return p;
79 p=p->next;
80 }
81 return NULL;
82}