My Project
Toggle main menu visibility
Loading...
Searching...
No Matches
Singular
htable.cc
Go to the documentation of this file.
1
/****************************************
2
* Computer Algebra System SINGULAR *
3
****************************************/
4
5
#include "
kernel/mod2.h
"
6
7
#include "
resources/hash_me.h
"
8
#include "
reporter/reporter.h
"
9
#include "
Singular/htable.h
"
10
11
stablerec
*
t_createTable
(
int
s
)
12
{
13
stablerec
* t=(
stablerec
*)
omAlloc
(
sizeof
(
stablerec
));
14
t->
max
=
s
;
15
t->
t
=(telem*)
omAlloc0
(
s
*
sizeof
(telem));
16
t->
ref
=1;
17
return
t;
18
}
19
20
void
t_destroyTable
(
stablerec
* t)
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
}
41
42
stablerec
*
copyTable
(
stablerec
* t)
43
{
44
t->
ref
++;
45
return
t;
46
}
47
48
char
*
stringTable
(
stablerec
* t)
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();
60
StringAppendS
(
s
);
61
omFree
(
s
);
62
StringAppendS
(
"\n"
);
63
p
=
p
->next;
64
}
65
}
66
return
StringEndS
();
67
}
68
69
/// find the entry to key s
70
telem
t_findTable
(
stablerec
* t,
const
char
*
s
)
71
{
72
uint32_t
h
=
hashlittle
(
s
,strlen(
s
));
73
h
=
h
%t->
max
;
74
telem
p
=t->
t
[
h
];
75
while
(
p
!=
NULL
)
76
{
77
if
(strcmp(
s
,
p
->key)==0)
return
p
;
78
p
=
p
->next;
79
}
80
return
NULL
;
81
}
82
83
/// find the data to key s
84
leftv
t_findTabelVal
(
stablerec
* t,
const
char
*
s
)
85
{
86
telem
p
=
t_findTable
(t,
s
);
87
if
(
p
==
NULL
)
return
NULL
;
88
return
&(
p
->val);
89
}
90
91
/// add a new entry (key s, data v) to table t, eats s, copies v
92
void
t_addTable
(
stablerec
* t,
char
*
s
,
leftv
v
)
93
{
94
uint32_t
h
=
hashlittle
(
s
,strlen(
s
));
95
telem
p
=(telem)
omAlloc
(
sizeof
(*
p
));
96
p
->next=
NULL
;
97
p
->key=
s
;
98
p
->val.Init();
99
p
->val.rtyp=
v
->Typ();
100
p
->val.data=
v
->CopyD();
101
p
->hash=
h
;
102
h
=
h
%t->
max
;
103
p
->next=t->
t
[
h
];
104
t->
t
[
h
]=
p
;
105
}
106
//-------------------------------------------------------
107
void
htable_Print
(
stablerec
*d)
108
{
109
stablerec
* lt=(
stablerec
*)d;
110
char
*
s
=
stringTable
(lt);
111
PrintS
(
s
);
112
omFree
(
s
);
113
int
cnt=0;
int
cnt2=0;
114
for
(
int
i
=0;
i
<lt->
max
;
i
++)
115
{
116
if
(lt->
t
[
i
]!=
NULL
)
117
{
118
cnt++;
119
telem
p
=lt->
t
[
i
];
120
while
(
p
!=
NULL
) { cnt2++;
p
=
p
->next;}
121
}
122
}
123
Print
(
"%d columns, %d entries, size:%d"
,cnt,cnt2,lt->
max
);
124
}
pp
CanonicalForm FACTORY_PUBLIC pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f ).
Definition
cf_gcd.cc:676
i
int i
Definition
cfEzgcd.cc:132
p
int p
Definition
cfModGcd.cc:4086
Print
#define Print
Definition
emacs.cc:80
s
const CanonicalForm int s
Definition
facAbsFact.cc:51
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition
facBivar.h:39
hashlittle
uint32_t hashlittle(const void *key, size_t length)
Definition
hash_me.c:68
hash_me.h
t_destroyTable
void t_destroyTable(stablerec *t)
Definition
htable.cc:20
stringTable
char * stringTable(stablerec *t)
Definition
htable.cc:48
t_createTable
stablerec * t_createTable(int s)
Definition
htable.cc:11
htable_Print
void htable_Print(stablerec *d)
Definition
htable.cc:107
t_findTabelVal
leftv t_findTabelVal(stablerec *t, const char *s)
find the data to key s
Definition
htable.cc:84
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
Definition
htable.cc:92
t_findTable
telem t_findTable(stablerec *t, const char *s)
find the entry to key s
Definition
htable.cc:70
copyTable
stablerec * copyTable(stablerec *t)
Definition
htable.cc:42
htable.h
stablerec::t
telem * t
Definition
htable.h:24
stablerec::max
int max
Definition
htable.h:25
stablerec::ref
int ref
Definition
htable.h:26
stablerec
Definition
htable.h:23
stelem
Definition
htable.h:15
h
STATIC_VAR Poly * h
Definition
janet.cc:971
mod2.h
omFreeSize
#define omFreeSize(addr, size)
Definition
omAllocDecl.h:260
omAlloc
#define omAlloc(size)
Definition
omAllocDecl.h:210
omFree
#define omFree(addr)
Definition
omAllocDecl.h:261
omAlloc0
#define omAlloc0(size)
Definition
omAllocDecl.h:211
NULL
#define NULL
Definition
omList.c:12
StringSetS
void StringSetS(const char *st)
Definition
reporter.cc:128
StringAppendS
void StringAppendS(const char *st)
Definition
reporter.cc:107
PrintS
void PrintS(const char *s)
Definition
reporter.cc:288
StringEndS
char * StringEndS()
Definition
reporter.cc:151
reporter.h
leftv
sleftv * leftv
Definition
structs.h:53
Generated on
for My Project by
doxygen 1.17.0
for
Singular