TreeNode.c

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 85 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Tree/Node.pm ↑ Summary lib/Tree/Node.xs »
1  
2 #include <stdlib.h>
3  
4 #include "EXTERN.h"
5 #include "perl.h"
6 #include "XSUB.h"
7 #include "ppport.h"
8  
9 #include "TreeNode.h"
10  
11 0 Node * new(int child_count)
12 {
13 Node * n;
14  
15 0 ▶ if ((child_count < 1) || (child_count > MAX_LEVEL))
Branch: 2 branches
BranchTrueFalseTotal
if ((child_count < 1) || (child_count > MAX_LEVEL)) 0 0 0
if ((child_count < 1) || (child_count > MAX_LEVEL)) 0 0 0
16 0 croak("child_count out of bounds: must be between [1..%d]", MAX_LEVEL);
17  
18 #if USE_MALLOC
19 n = malloc((size_t) NODESIZE(child_count));
20 if (n == NULL)
21 croak("unable to a allocate memory");
22 #else
23 0 Newc(1, n, NODESIZE(child_count), char, Node);
24 #endif
25  
26 0 n->child_count = child_count;
27  
28 0 n->key = &PL_sv_undef;
29 0 n->value = &PL_sv_undef;
30  
31 0 return n;
32 }
33  
34 0 void DESTROY(Node* n)
35 {
36 0 SvREFCNT_dec(n->key);
37 0 SvREFCNT_dec(n->value);
38  
39 #if USE_MALLOC
40 free(n);
41 #else
42 0 Safefree(n);
43 #endif
44 0 }
45  
46 0 int child_count(Node * n)
47 {
48 0 return n->child_count;
49 }
50  
51 0 SV* get_child(Node * n, int index)
52 {
53 0 ▶ if ((index >= n->child_count) || (index < 0))
Branch: 2 branches
BranchTrueFalseTotal
if ((index >= n->child_count) || (index < 0)) 0 0 0
if ((index >= n->child_count) || (index < 0)) 0 0 0
54 0 croak("index out of bounds: must be between [0..%d]", n->child_count-1);
55  
56 0 return SvREFCNT_inc(n->next[index]);
57 }
58  
59 0 SV* get_child_or_undef(Node * n, int index)
60 {
61 0 ▶ if ((index >= n->child_count) || (index < 0))
Branch: 2 branches
BranchTrueFalseTotal
if ((index >= n->child_count) || (index < 0)) 0 0 0
if ((index >= n->child_count) || (index < 0)) 0 0 0
62 0 return &PL_sv_undef;
63 else
64 0 return SvREFCNT_inc(n->next[index]);
65 }
66  
67 0 void set_child(Node* n, int index, SV* t)
68 {
69 0 ▶ if ((index >= n->child_count) || (index < 0))
Branch: 2 branches
BranchTrueFalseTotal
if ((index >= n->child_count) || (index < 0)) 0 0 0
if ((index >= n->child_count) || (index < 0)) 0 0 0
70 0 croak("index out of bounds: must be between [0..%d]", n->child_count-1);
71  
72 0 ▶ if (SvOK(n->next[index]))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(n->next[index])) 0 0 0
73 0 sv_setsv(n->next[index], t);
74 else
75 0 n->next[index] = newSVsv(t);
76 0 }
77  
78 0 void set_key(Node *n, SV* k)
79 {
80 0 ▶ if (SvOK(n->key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(n->key)) { 0 0 0
81 0 croak("key is already set");
82 }
83 else {
84 0 n->key = newRV_inc(k);
85 }
86 0 }
87  
88 0 void force_set_key(Node *n, SV* k)
89 {
90 0 ▶ if (SvOK(n->key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(n->key)) { 0 0 0
91 0 warn("key is already set");
92 }
93 0 n->key = newRV_inc(k);
94 0 }
95  
96 0 SV* get_key(Node *n)
97 {
98 0 ▶ if (SvOK(n->key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(n->key)) { 0 0 0
99 0 return SvREFCNT_inc(SvRV(n->key));
100 }
101 else {
102 0 return &PL_sv_undef;
103 }
104 }
105  
106 0 I32 key_cmp(Node* n, SV* k)
107 {
108 0 ▶ if (SvOK(n->key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(n->key)) { 0 0 0
109 0 return sv_cmp(SvRV(n->key), k);
110 }
111 else {
112 0 return -1;
113 }
114 }
115  
116 0 void set_value(Node *n, SV* v)
117 {
118 0 n->value = newRV_inc(v);
119 0 }
120  
121 0 SV* get_value(Node *n)
122 {
123 0 ▶ if (SvOK(n->key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(n->key)) { 0 0 0
124 0 return SvREFCNT_inc(SvRV(n->value));
125 }
126 else {
127 0 return &PL_sv_undef;
128 }
129 }
130  
131 0 int _allocated(Node* n)
132 {
133 0 return NODESIZE(n->child_count);
134 }
« blib/lib/Tree/Node.pm ↑ Summary lib/Tree/Node.xs »