| 1 |
|
| # HAMT::Vector. Every method that "changes" a vector gives the change a |
| 2 |
|
| # struct of its own that starts out sharing the receiver's nodes, so the |
| 3 |
|
| # first thing it touches is copied and the receiver never moves. |
| 4 |
|
| |
| 5 |
|
| MODULE = HAMT PACKAGE = HAMT::Vector |
| 6 |
|
| |
| 7 |
|
| void |
| 8 |
|
| new(klass, ...) |
| 9 |
|
| SV *klass |
| 10 |
|
| PREINIT: |
| 11 |
|
| hamt_vec *v; |
| 12 |
|
| SV *obj; |
| 13 |
|
| I32 i; |
| 14 |
|
| CODE: |
| 15 |
3078 |
| obj = hamt_vec_handle_new(aTHX_ hamt_class_stash(aTHX_ klass), NULL, &v, |
| 16 |
|
| "HAMT::Vector::new"); |
| 17 |
269132 |
▶ | for (i = 1; i < items; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i < items; i++) |
266055 |
3077 |
269132 |
|
| 18 |
266055 |
| hamt_xs_vec_push(aTHX_ v, ST(i), "HAMT::Vector::new"); |
| 19 |
3077 |
| ST(0) = obj; |
| 20 |
3077 |
| XSRETURN(1); |
| 21 |
|
| |
| 22 |
|
| void |
| 23 |
|
| push(self, ...) |
| 24 |
|
| SV *self |
| 25 |
|
| PREINIT: |
| 26 |
|
| hamt_vec *v, *n; |
| 27 |
|
| SV *obj; |
| 28 |
|
| I32 i; |
| 29 |
|
| CODE: |
| 30 |
92130 |
| v = hamt_vec_handle(aTHX_ self, "HAMT::Vector::push"); |
| 31 |
92124 |
▶ | if (GIMME_V == G_VOID) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (GIMME_V == G_VOID) { |
2 |
92122 |
92124 |
|
| 32 |
2 |
| hamt_void_warn(aTHX_ "HAMT::Vector::push"); |
| 33 |
2 |
| XSRETURN_EMPTY; |
| 34 |
|
| } |
| 35 |
92122 |
▶ | if (items == 1) XSRETURN(1); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items == 1) XSRETURN(1); |
1 |
92121 |
92122 |
|
| 36 |
92121 |
| obj = hamt_vec_handle_new(aTHX_ SvSTASH(SvRV(self)), v, &n, "HAMT::Vector::push"); |
| 37 |
184245 |
▶ | for (i = 1; i < items; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i < items; i++) |
92125 |
92120 |
184245 |
|
| 38 |
92125 |
| hamt_xs_vec_push(aTHX_ n, ST(i), "HAMT::Vector::push"); |
| 39 |
92120 |
| ST(0) = obj; |
| 40 |
92120 |
| XSRETURN(1); |
| 41 |
|
| |
| 42 |
|
| void |
| 43 |
|
| set(self, index, value) |
| 44 |
|
| SV *self |
| 45 |
|
| SV *index |
| 46 |
|
| SV *value |
| 47 |
|
| PREINIT: |
| 48 |
|
| hamt_vec *v, *n; |
| 49 |
|
| size_t i; |
| 50 |
|
| SV *obj; |
| 51 |
|
| CODE: |
| 52 |
25298 |
| v = hamt_vec_handle(aTHX_ self, "HAMT::Vector::set"); |
| 53 |
25292 |
▶ | if (!hamt_xs_index(aTHX_ index, v->count, &i)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hamt_xs_index(aTHX_ index, v->count, &i)) |
6 |
25286 |
25292 |
|
| 54 |
6 |
| croak("HAMT::Vector::set: index %" IVdf " is out of range for %" UVuf " elements", |
| 55 |
|
| SvIV(index), (UV)v->count); |
| 56 |
25286 |
▶ | if (GIMME_V == G_VOID) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (GIMME_V == G_VOID) { |
1 |
25285 |
25286 |
|
| 57 |
1 |
| hamt_void_warn(aTHX_ "HAMT::Vector::set"); |
| 58 |
1 |
| XSRETURN_EMPTY; |
| 59 |
|
| } |
| 60 |
25285 |
▶ | if (hamt_vec_get(v, i) == (void *)value) XSRETURN(1); |
Branch: 1 branch
| Branch | True | False | Total |
| if (hamt_vec_get(v, i) == (void *)value) XSRETURN(1); |
1 |
25284 |
25285 |
|
| 61 |
25284 |
| obj = hamt_vec_handle_new(aTHX_ SvSTASH(SvRV(self)), v, &n, "HAMT::Vector::set"); |
| 62 |
25284 |
| hamt_xs_vec_set(aTHX_ n, i, value, "HAMT::Vector::set"); |
| 63 |
25284 |
| ST(0) = obj; |
| 64 |
25284 |
| XSRETURN(1); |
| 65 |
|
| |
| 66 |
|
| void |
| 67 |
|
| pop(self) |
| 68 |
|
| SV *self |
| 69 |
|
| PREINIT: |
| 70 |
|
| hamt_vec *v, *n; |
| 71 |
|
| SV *obj; |
| 72 |
|
| CODE: |
| 73 |
40315 |
| v = hamt_vec_handle(aTHX_ self, "HAMT::Vector::pop"); |
| 74 |
40309 |
▶ | if (GIMME_V == G_VOID) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (GIMME_V == G_VOID) { |
2 |
40307 |
40309 |
|
| 75 |
2 |
| hamt_void_warn(aTHX_ "HAMT::Vector::pop"); |
| 76 |
2 |
| XSRETURN_EMPTY; |
| 77 |
|
| } |
| 78 |
40307 |
▶ | if (v->count == 0) XSRETURN(1); |
Branch: 1 branch
| Branch | True | False | Total |
| if (v->count == 0) XSRETURN(1); |
1 |
40306 |
40307 |
|
| 79 |
40306 |
| obj = hamt_vec_handle_new(aTHX_ SvSTASH(SvRV(self)), v, &n, "HAMT::Vector::pop"); |
| 80 |
40306 |
| hamt_xs_vec_pop(aTHX_ n, "HAMT::Vector::pop"); |
| 81 |
40306 |
| ST(0) = obj; |
| 82 |
40306 |
| XSRETURN(1); |
| 83 |
|
| |
| 84 |
|
| void |
| 85 |
|
| get(self, index) |
| 86 |
|
| SV *self |
| 87 |
|
| SV *index |
| 88 |
|
| PREINIT: |
| 89 |
|
| hamt_vec *v; |
| 90 |
|
| size_t i; |
| 91 |
|
| CODE: |
| 92 |
26383 |
| v = hamt_vec_handle(aTHX_ self, "HAMT::Vector::get"); |
| 93 |
26377 |
| ST(0) = hamt_xs_index(aTHX_ index, v->count, &i) |
| 94 |
26125 |
| ? sv_2mortal(SvREFCNT_inc_simple_NN((SV *)hamt_vec_get(v, i))) |
| 95 |
26377 |
▶ | : sv_newmortal(); |
Branch: 1 branch
| Branch | True | False | Total |
| : sv_newmortal(); |
26125 |
252 |
26377 |
|
| 96 |
26377 |
| XSRETURN(1); |
| 97 |
|
| |
| 98 |
|
| void |
| 99 |
|
| first(self) |
| 100 |
|
| SV *self |
| 101 |
|
| ALIAS: |
| 102 |
|
| last = 1 |
| 103 |
|
| PREINIT: |
| 104 |
|
| hamt_vec *v; |
| 105 |
|
| CODE: |
| 106 |
2109 |
▶ | v = hamt_vec_handle(aTHX_ self, ix ? "HAMT::Vector::last" : "HAMT::Vector::first"); |
Branch: 1 branch
| Branch | True | False | Total |
| v = hamt_vec_handle(aTHX_ self, ix ? "HAMT::Vector::last" : "HAMT::Vector::first"); |
1066 |
1043 |
2109 |
|
| 107 |
4194 |
| ST(0) = v->count |
| 108 |
2095 |
▶ | ? sv_2mortal(SvREFCNT_inc_simple_NN((SV *)hamt_vec_get(v, ix ? v->count - 1 : 0))) |
Branch: 2 branches
| Branch | True | False | Total |
| ? sv_2mortal(SvREFCNT_inc_simple_NN((SV *)hamt_vec_get(v, ix ? v->count - 1 : 0))) |
1059 |
1036 |
2095 |
| ? sv_2mortal(SvREFCNT_inc_simple_NN((SV *)hamt_vec_get(v, ix ? v->count - 1 : 0))) |
1059 |
1036 |
2095 |
|
| 109 |
2097 |
▶ | : sv_newmortal(); |
Branch: 1 branch
| Branch | True | False | Total |
| : sv_newmortal(); |
2095 |
2 |
2097 |
|
| 110 |
2097 |
| XSRETURN(1); |
| 111 |
|
| |
| 112 |
|
| void |
| 113 |
|
| count(self) |
| 114 |
|
| SV *self |
| 115 |
|
| PREINIT: |
| 116 |
|
| hamt_vec *v; |
| 117 |
|
| CODE: |
| 118 |
231782 |
| v = hamt_vec_handle(aTHX_ self, "HAMT::Vector::count"); |
| 119 |
231776 |
| ST(0) = sv_2mortal(newSVuv((UV)v->count)); |
| 120 |
231776 |
| XSRETURN(1); |
| 121 |
|
| |
| 122 |
|
| # Every value, in order: the stored scalars themselves. In scalar context, |
| 123 |
|
| # how many. |
| 124 |
|
| void |
| 125 |
|
| list(self) |
| 126 |
|
| SV *self |
| 127 |
|
| PREINIT: |
| 128 |
|
| hamt_vec *v; |
| 129 |
|
| hamt_vec_iter it; |
| 130 |
|
| void *const *run; |
| 131 |
|
| size_t start; |
| 132 |
|
| uint32_t n, i; |
| 133 |
|
| PPCODE: |
| 134 |
64522 |
| v = hamt_vec_handle(aTHX_ self, "HAMT::Vector::list"); |
| 135 |
64516 |
▶ | if (GIMME_V == G_VOID) XSRETURN_EMPTY; |
Branch: 1 branch
| Branch | True | False | Total |
| if (GIMME_V == G_VOID) XSRETURN_EMPTY; |
1 |
64515 |
64516 |
|
| 136 |
64515 |
▶ | if (GIMME_V == G_SCALAR) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (GIMME_V == G_SCALAR) { |
1 |
64514 |
64515 |
|
| 137 |
1 |
| PUSHs(sv_2mortal(newSVuv((UV)v->count))); |
| 138 |
1 |
| XSRETURN(1); |
| 139 |
|
| } |
| 140 |
64514 |
▶ | if (v->count > ((size_t)-1 >> 2)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (v->count > ((size_t)-1 >> 2)) |
0 |
64514 |
64514 |
|
| 141 |
0 |
| croak("HAMT::Vector::list: too many elements for one list"); |
| 142 |
64514 |
▶ | EXTEND(SP, (SSize_t)v->count); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, (SSize_t)v->count); |
64514 |
0 |
64514 |
| EXTEND(SP, (SSize_t)v->count); |
10 |
64504 |
64514 |
|
| 143 |
64514 |
| hamt_vec_iter_init(&it, v); |
| 144 |
424984 |
▶ | while ((run = hamt_vec_iter_next(&it, &start, &n))) |
Branch: 1 branch
| Branch | True | False | Total |
| while ((run = hamt_vec_iter_next(&it, &start, &n))) |
360470 |
64514 |
424984 |
|
| 145 |
10212800 |
▶ | for (i = 0; i < n; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) |
9852330 |
360470 |
10212800 |
|
| 146 |
9852330 |
| PUSHs(sv_2mortal(SvREFCNT_inc_simple_NN((SV *)run[i]))); |
| 147 |
|
| |
| 148 |
|
| # A new, ordinary array holding a copy of every value. |
| 149 |
|
| void |
| 150 |
|
| to_array(self) |
| 151 |
|
| SV *self |
| 152 |
|
| PREINIT: |
| 153 |
|
| hamt_vec *v; |
| 154 |
|
| hamt_vec_iter it; |
| 155 |
|
| void *const *run; |
| 156 |
|
| size_t start; |
| 157 |
|
| uint32_t n, i; |
| 158 |
|
| AV *av; |
| 159 |
|
| CODE: |
| 160 |
11 |
| v = hamt_vec_handle(aTHX_ self, "HAMT::Vector::to_array"); |
| 161 |
5 |
| av = newAV(); |
| 162 |
5 |
| ST(0) = sv_2mortal(newRV_noinc((SV *)av)); |
| 163 |
5 |
▶ | if (v->count) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (v->count) { |
4 |
1 |
5 |
|
| 164 |
4 |
▶ | if (v->count > (size_t)I32_MAX) croak("HAMT::Vector::to_array: too many elements for an array"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (v->count > (size_t)I32_MAX) croak("HAMT::Vector::to_array: too many elements for an array"); |
0 |
4 |
4 |
|
| 165 |
4 |
| av_extend(av, (I32)(v->count - 1)); |
| 166 |
|
| } |
| 167 |
5 |
| hamt_vec_iter_init(&it, v); |
| 168 |
74 |
▶ | while ((run = hamt_vec_iter_next(&it, &start, &n))) |
Branch: 1 branch
| Branch | True | False | Total |
| while ((run = hamt_vec_iter_next(&it, &start, &n))) |
69 |
5 |
74 |
|
| 169 |
2161 |
▶ | for (i = 0; i < n; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) |
2092 |
69 |
2161 |
|
| 170 |
2092 |
| av_push(av, newSVsv((SV *)run[i])); |
| 171 |
5 |
| XSRETURN(1); |
| 172 |
|
| |
| 173 |
|
| # Every value of this vector followed by every value of the other. |
| 174 |
|
| void |
| 175 |
|
| concat(self, other) |
| 176 |
|
| SV *self |
| 177 |
|
| SV *other |
| 178 |
|
| PREINIT: |
| 179 |
|
| hamt_vec *v, *o, *n, res; |
| 180 |
|
| SV *obj; |
| 181 |
|
| CODE: |
| 182 |
3239 |
| v = hamt_vec_handle(aTHX_ self, "HAMT::Vector::concat"); |
| 183 |
3238 |
| o = hamt_vec_handle(aTHX_ other, "HAMT::Vector::concat"); |
| 184 |
3236 |
▶ | if (GIMME_V == G_VOID) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (GIMME_V == G_VOID) { |
1 |
3235 |
3236 |
|
| 185 |
1 |
| hamt_void_warn(aTHX_ "HAMT::Vector::concat"); |
| 186 |
1 |
| XSRETURN_EMPTY; |
| 187 |
|
| } |
| 188 |
3235 |
▶ | if (o->count == 0) XSRETURN(1); |
Branch: 1 branch
| Branch | True | False | Total |
| if (o->count == 0) XSRETURN(1); |
20 |
3215 |
3235 |
|
| 189 |
3215 |
▶ | if (v->count == 0 && SvSTASH(SvRV(other)) == SvSTASH(SvRV(self))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (v->count == 0 && SvSTASH(SvRV(other)) == SvSTASH(SvRV(self))) { |
20 |
3195 |
3215 |
| if (v->count == 0 && SvSTASH(SvRV(other)) == SvSTASH(SvRV(self))) { |
19 |
1 |
20 |
|
| 190 |
19 |
| ST(0) = other; |
| 191 |
19 |
| XSRETURN(1); |
| 192 |
|
| } |
| 193 |
3196 |
| obj = hamt_vec_handle_new(aTHX_ SvSTASH(SvRV(self)), NULL, &n, "HAMT::Vector::concat"); |
| 194 |
3196 |
▶ | if (hamt_vec_concat(HAMT_CX, &res, v, o)) croak("HAMT::Vector::concat: out of memory"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (hamt_vec_concat(HAMT_CX, &res, v, o)) croak("HAMT::Vector::concat: out of memory"); |
0 |
3196 |
3196 |
|
| 195 |
3196 |
| *n = res; |
| 196 |
3196 |
| ST(0) = obj; |
| 197 |
3196 |
| XSRETURN(1); |
| 198 |
|
| |
| 199 |
|
| # The values from one index on, or as many of them as asked for. It clamps: |
| 200 |
|
| # a length that runs past the end stops at the end, and a start past the end |
| 201 |
|
| # is an empty vector. |
| 202 |
|
| void |
| 203 |
|
| slice(self, from, ...) |
| 204 |
|
| SV *self |
| 205 |
|
| SV *from |
| 206 |
|
| PREINIT: |
| 207 |
|
| hamt_vec *v, *n, res; |
| 208 |
|
| IV f, l; |
| 209 |
|
| size_t start, len; |
| 210 |
|
| SV *obj; |
| 211 |
|
| CODE: |
| 212 |
64596 |
| v = hamt_vec_handle(aTHX_ self, "HAMT::Vector::slice"); |
| 213 |
64595 |
▶ | if (items > 3) croak("HAMT::Vector::slice: too many arguments"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 3) croak("HAMT::Vector::slice: too many arguments"); |
1 |
64594 |
64595 |
|
| 214 |
64594 |
| f = SvIV(from); |
| 215 |
64594 |
▶ | if (f < 0) start = (UV)(-(f + 1)) >= (UV)v->count ? 0 : v->count - (size_t)(-(f + 1)) - 1; |
Branch: 2 branches
| Branch | True | False | Total |
| if (f < 0) start = (UV)(-(f + 1)) >= (UV)v->count ? 0 : v->count - (size_t)(-(f + 1)) - 1; |
4 |
64590 |
64594 |
| if (f < 0) start = (UV)(-(f + 1)) >= (UV)v->count ? 0 : v->count - (size_t)(-(f + 1)) - 1; |
3 |
1 |
4 |
|
| 216 |
64590 |
| else start = (UV)f > (UV)v->count ? v->count : (size_t)f; |
| 217 |
64594 |
| len = v->count - start; |
| 218 |
64594 |
▶ | if (items == 3 && SvOK(ST(2))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (items == 3 && SvOK(ST(2))) { |
64588 |
6 |
64594 |
| if (items == 3 && SvOK(ST(2))) { |
64587 |
1 |
64588 |
|
| 219 |
64587 |
| l = SvIV(ST(2)); |
| 220 |
64587 |
▶ | if (l < 0) croak("HAMT::Vector::slice: length %" IVdf " is negative", l); |
Branch: 1 branch
| Branch | True | False | Total |
| if (l < 0) croak("HAMT::Vector::slice: length %" IVdf " is negative", l); |
1 |
64586 |
64587 |
|
| 221 |
64586 |
▶ | if ((UV)l < (UV)len) len = (size_t)l; |
Branch: 1 branch
| Branch | True | False | Total |
| if ((UV)l < (UV)len) len = (size_t)l; |
61658 |
2928 |
64586 |
|
| 222 |
|
| } |
| 223 |
64593 |
▶ | if (GIMME_V == G_VOID) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (GIMME_V == G_VOID) { |
1 |
64592 |
64593 |
|
| 224 |
1 |
| hamt_void_warn(aTHX_ "HAMT::Vector::slice"); |
| 225 |
1 |
| XSRETURN_EMPTY; |
| 226 |
|
| } |
| 227 |
64592 |
▶ | if (len == v->count) XSRETURN(1); |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == v->count) XSRETURN(1); |
167 |
64425 |
64592 |
|
| 228 |
64425 |
| obj = hamt_vec_handle_new(aTHX_ SvSTASH(SvRV(self)), NULL, &n, "HAMT::Vector::slice"); |
| 229 |
64425 |
▶ | if (len) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len) { |
61866 |
2559 |
64425 |
|
| 230 |
61866 |
▶ | if (hamt_vec_slice(HAMT_CX, &res, v, start, len)) croak("HAMT::Vector::slice: out of memory"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (hamt_vec_slice(HAMT_CX, &res, v, start, len)) croak("HAMT::Vector::slice: out of memory"); |
0 |
61866 |
61866 |
|
| 231 |
61866 |
| *n = res; |
| 232 |
|
| } |
| 233 |
64425 |
| ST(0) = obj; |
| 234 |
64425 |
| XSRETURN(1); |
| 235 |
|
| |
| 236 |
|
| # The vector with values put in before an index. |
| 237 |
|
| void |
| 238 |
|
| insert(self, index, ...) |
| 239 |
|
| SV *self |
| 240 |
|
| SV *index |
| 241 |
|
| PREINIT: |
| 242 |
|
| hamt_vec *v, *n, *mid; |
| 243 |
|
| size_t at; |
| 244 |
|
| SV *obj; |
| 245 |
|
| I32 i; |
| 246 |
|
| CODE: |
| 247 |
4771 |
| v = hamt_vec_handle(aTHX_ self, "HAMT::Vector::insert"); |
| 248 |
4770 |
▶ | if (!hamt_xs_gap(aTHX_ index, v->count, &at)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hamt_xs_gap(aTHX_ index, v->count, &at)) |
4 |
4766 |
4770 |
|
| 249 |
4 |
| croak("HAMT::Vector::insert: index %" IVdf " is out of range for %" UVuf " elements", |
| 250 |
|
| SvIV(index), (UV)v->count); |
| 251 |
4766 |
▶ | if (GIMME_V == G_VOID) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (GIMME_V == G_VOID) { |
1 |
4765 |
4766 |
|
| 252 |
1 |
| hamt_void_warn(aTHX_ "HAMT::Vector::insert"); |
| 253 |
1 |
| XSRETURN_EMPTY; |
| 254 |
|
| } |
| 255 |
4765 |
▶ | if (items == 2) XSRETURN(1); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items == 2) XSRETURN(1); |
1 |
4764 |
4765 |
|
| 256 |
|
| /* The new values go into a vector of their own first, in a handle, |
| 257 |
|
| * so that one of them dying as it is read leaves nothing behind. */ |
| 258 |
4764 |
| hamt_vec_handle_new(aTHX_ SvSTASH(SvRV(self)), NULL, &mid, "HAMT::Vector::insert"); |
| 259 |
13871 |
▶ | for (i = 2; i < items; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 2; i < items; i++) |
9107 |
4764 |
13871 |
|
| 260 |
9107 |
| hamt_xs_vec_push(aTHX_ mid, ST(i), "HAMT::Vector::insert"); |
| 261 |
4764 |
| v = hamt_vec_handle(aTHX_ self, "HAMT::Vector::insert"); |
| 262 |
4764 |
| obj = hamt_vec_handle_new(aTHX_ SvSTASH(SvRV(self)), NULL, &n, "HAMT::Vector::insert"); |
| 263 |
4764 |
| hamt_xs_vec_splice(aTHX_ n, v, at, 0, mid, "HAMT::Vector::insert"); |
| 264 |
4764 |
| ST(0) = obj; |
| 265 |
4764 |
| XSRETURN(1); |
| 266 |
|
| |
| 267 |
|
| # The vector without the value at an index, or without several from there. |
| 268 |
|
| void |
| 269 |
|
| remove(self, index, ...) |
| 270 |
|
| SV *self |
| 271 |
|
| SV *index |
| 272 |
|
| PREINIT: |
| 273 |
|
| hamt_vec *v, *n; |
| 274 |
2410 |
| size_t at, len = 1; |
| 275 |
|
| IV l; |
| 276 |
|
| SV *obj; |
| 277 |
|
| CODE: |
| 278 |
2410 |
| v = hamt_vec_handle(aTHX_ self, "HAMT::Vector::remove"); |
| 279 |
2409 |
▶ | if (items > 3) croak("HAMT::Vector::remove: too many arguments"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 3) croak("HAMT::Vector::remove: too many arguments"); |
0 |
2409 |
2409 |
|
| 280 |
2409 |
▶ | if (items == 3 && SvOK(ST(2))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (items == 3 && SvOK(ST(2))) { |
2400 |
9 |
2409 |
| if (items == 3 && SvOK(ST(2))) { |
2400 |
0 |
2400 |
|
| 281 |
2400 |
| l = SvIV(ST(2)); |
| 282 |
2400 |
▶ | if (l < 0) croak("HAMT::Vector::remove: length %" IVdf " is negative", l); |
Branch: 1 branch
| Branch | True | False | Total |
| if (l < 0) croak("HAMT::Vector::remove: length %" IVdf " is negative", l); |
1 |
2399 |
2400 |
|
| 283 |
2399 |
| len = (size_t)l; |
| 284 |
|
| } |
| 285 |
2408 |
▶ | if (GIMME_V == G_VOID) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (GIMME_V == G_VOID) { |
1 |
2407 |
2408 |
|
| 286 |
1 |
| hamt_void_warn(aTHX_ "HAMT::Vector::remove"); |
| 287 |
1 |
| XSRETURN_EMPTY; |
| 288 |
|
| } |
| 289 |
|
| /* An index that names nothing removes nothing. */ |
| 290 |
2407 |
▶ | if (!hamt_xs_index(aTHX_ index, v->count, &at) || len == 0) XSRETURN(1); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!hamt_xs_index(aTHX_ index, v->count, &at) || len == 0) XSRETURN(1); |
2405 |
2 |
2407 |
| if (!hamt_xs_index(aTHX_ index, v->count, &at) || len == 0) XSRETURN(1); |
1 |
2404 |
2405 |
|
| 291 |
2404 |
▶ | if (len > v->count - at) len = v->count - at; |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > v->count - at) len = v->count - at; |
484 |
1920 |
2404 |
|
| 292 |
2404 |
| obj = hamt_vec_handle_new(aTHX_ SvSTASH(SvRV(self)), NULL, &n, "HAMT::Vector::remove"); |
| 293 |
2404 |
| hamt_xs_vec_splice(aTHX_ n, v, at, len, NULL, "HAMT::Vector::remove"); |
| 294 |
2404 |
| ST(0) = obj; |
| 295 |
2404 |
| XSRETURN(1); |
| 296 |
|
| |
| 297 |
|
| # Calls the sub with each value and its index. Returns the vector. |
| 298 |
|
| void |
| 299 |
|
| each(self, code) |
| 300 |
|
| SV *self |
| 301 |
|
| SV *code |
| 302 |
|
| PREINIT: |
| 303 |
|
| hamt_vec *v, *held; |
| 304 |
|
| hamt_vec_iter it; |
| 305 |
|
| void *const *run; |
| 306 |
|
| size_t start; |
| 307 |
|
| uint32_t n, i; |
| 308 |
25 |
| SV *idxsv = NULL, *args[2], *err = NULL; |
| 309 |
25 |
| int how = HAMT_XS_RETURNED; |
| 310 |
|
| CODE: |
| 311 |
25 |
| v = hamt_vec_handle(aTHX_ self, "HAMT::Vector::each"); |
| 312 |
25 |
| hamt_xs_need_code(aTHX_ code, "HAMT::Vector::each"); |
| 313 |
24 |
| ENTER; |
| 314 |
24 |
| SAVETMPS; |
| 315 |
24 |
| held = hamt_xs_hold_vec(aTHX_ v, "HAMT::Vector::each"); |
| 316 |
24 |
| hamt_xs_walk_enter(aTHX); |
| 317 |
24 |
| hamt_vec_iter_init(&it, held); |
| 318 |
351 |
▶ | while (how != HAMT_XS_LAST && !err && (run = hamt_vec_iter_next(&it, &start, &n))) { |
Branch: 3 branches
| Branch | True | False | Total |
| while (how != HAMT_XS_LAST && !err && (run = hamt_vec_iter_next(&it, &start, &n))) { |
345 |
6 |
351 |
| while (how != HAMT_XS_LAST && !err && (run = hamt_vec_iter_next(&it, &start, &n))) { |
338 |
7 |
345 |
| while (how != HAMT_XS_LAST && !err && (run = hamt_vec_iter_next(&it, &start, &n))) { |
327 |
11 |
338 |
|
| 319 |
10200 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
9886 |
314 |
10200 |
|
| 320 |
9886 |
| idxsv = hamt_xs_scratch(aTHX_ idxsv); |
| 321 |
9886 |
| sv_setuv(idxsv, (UV)(start + i)); |
| 322 |
9886 |
| args[0] = (SV *)run[i]; |
| 323 |
9886 |
| args[1] = idxsv; |
| 324 |
9886 |
| how = hamt_xs_call(aTHX_ code, args, 2, NULL); |
| 325 |
9886 |
▶ | if (how == HAMT_XS_LAST || (err = hamt_xs_call_err(aTHX_ how, 1))) break; |
Branch: 2 branches
| Branch | True | False | Total |
| if (how == HAMT_XS_LAST || (err = hamt_xs_call_err(aTHX_ how, 1))) break; |
9880 |
6 |
9886 |
| if (how == HAMT_XS_LAST || (err = hamt_xs_call_err(aTHX_ how, 1))) break; |
9873 |
7 |
9880 |
|
| 326 |
|
| } |
| 327 |
|
| } |
| 328 |
24 |
| hamt_xs_call_leave(aTHX); |
| 329 |
24 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
24 |
0 |
24 |
|
| 330 |
24 |
| LEAVE; |
| 331 |
24 |
▶ | if (err) hamt_xs_rethrow(aTHX_ err); |
Branch: 1 branch
| Branch | True | False | Total |
| if (err) hamt_xs_rethrow(aTHX_ err); |
7 |
17 |
24 |
|
| 332 |
17 |
| XSRETURN(1); |
| 333 |
|
| |
| 334 |
|
| # True when the other thing is a vector of equal values in the same order. |
| 335 |
|
| void |
| 336 |
|
| equals(self, other, ...) |
| 337 |
|
| SV *self |
| 338 |
|
| SV *other |
| 339 |
|
| PREINIT: |
| 340 |
|
| hamt_vec *v, *o, *ha, *hb; |
| 341 |
|
| hamt_eq_ctx c; |
| 342 |
|
| int rc; |
| 343 |
|
| CODE: |
| 344 |
38 |
| v = hamt_vec_handle(aTHX_ self, "HAMT::Vector::equals"); |
| 345 |
38 |
▶ | if (items > 3) croak("HAMT::Vector::equals: too many arguments"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 3) croak("HAMT::Vector::equals: too many arguments"); |
0 |
38 |
38 |
|
| 346 |
38 |
▶ | if (items == 3) hamt_xs_need_code(aTHX_ ST(2), "HAMT::Vector::equals"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items == 3) hamt_xs_need_code(aTHX_ ST(2), "HAMT::Vector::equals"); |
12 |
26 |
38 |
|
| 347 |
37 |
| o = hamt_vec_handle_try(aTHX_ other); |
| 348 |
37 |
▶ | if (!o || o->count != v->count) XSRETURN_NO; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!o || o->count != v->count) XSRETURN_NO; |
34 |
3 |
37 |
| if (!o || o->count != v->count) XSRETURN_NO; |
2 |
32 |
34 |
|
| 349 |
32 |
| c.cx = HAMT_CX; |
| 350 |
32 |
▶ | c.eq = items == 3 ? hamt_xs_eq_cb : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| c.eq = items == 3 ? hamt_xs_eq_cb : NULL; |
11 |
21 |
32 |
|
| 351 |
32 |
▶ | c.ud = items == 3 ? (void *)ST(2) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| c.ud = items == 3 ? (void *)ST(2) : NULL; |
11 |
21 |
32 |
|
| 352 |
32 |
| c.visits = 0; |
| 353 |
32 |
| ENTER; |
| 354 |
32 |
| ha = hamt_xs_hold_vec(aTHX_ v, "HAMT::Vector::equals"); |
| 355 |
32 |
| hb = hamt_xs_hold_vec(aTHX_ o, "HAMT::Vector::equals"); |
| 356 |
32 |
| rc = hamt_vec_equal(&c, ha, hb); |
| 357 |
24 |
| LEAVE; |
| 358 |
24 |
▶ | ST(0) = boolSV(rc > 0); |
Branch: 1 branch
| Branch | True | False | Total |
| ST(0) = boolSV(rc > 0); |
16 |
8 |
24 |
|
| 359 |
24 |
| XSRETURN(1); |
| 360 |
|
| |
| 361 |
|
| void |
| 362 |
|
| transient(self) |
| 363 |
|
| SV *self |
| 364 |
|
| PREINIT: |
| 365 |
|
| hamt_vec *v; |
| 366 |
|
| hamt_vtxn *t; |
| 367 |
|
| SV *inner, *rv; |
| 368 |
|
| MAGIC *mg; |
| 369 |
|
| CODE: |
| 370 |
311 |
| v = hamt_vec_handle(aTHX_ self, "HAMT::Vector::transient"); |
| 371 |
305 |
| t = (hamt_vtxn *)HAMT_ALLOC(HAMT_CX, sizeof(hamt_vtxn)); |
| 372 |
305 |
▶ | if (!t) croak("HAMT::Vector::transient: out of memory"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!t) croak("HAMT::Vector::transient: out of memory"); |
0 |
305 |
305 |
|
| 373 |
305 |
| hamt_vec_share(&t->v, v); |
| 374 |
305 |
| t->origin = (HV *)SvREFCNT_inc_simple_NN((SV *)SvSTASH(SvRV(self))); |
| 375 |
305 |
| t->open = 1; |
| 376 |
305 |
| inner = newSV(0); |
| 377 |
305 |
| mg = sv_magicext(inner, NULL, PERL_MAGIC_ext, &hamt_vec_txn_vtbl, (const char *)t, 0); |
| 378 |
305 |
| mg->mg_flags |= MGf_DUP; |
| 379 |
305 |
| rv = sv_2mortal(newRV_noinc(inner)); |
| 380 |
305 |
| sv_bless(rv, gv_stashpvs("HAMT::Vector::Transient", GV_ADD)); |
| 381 |
305 |
| ST(0) = rv; |
| 382 |
305 |
| XSRETURN(1); |
| 383 |
|
| |
| 384 |
|
| void |
| 385 |
|
| _check(self) |
| 386 |
|
| SV *self |
| 387 |
|
| PREINIT: |
| 388 |
|
| hamt_vec *v; |
| 389 |
|
| CODE: |
| 390 |
80685 |
| v = hamt_vec_handle(aTHX_ self, "HAMT::Vector::_check"); |
| 391 |
80679 |
| ST(0) = sv_2mortal(newSViv((IV)hamt_vec_check(v))); |
| 392 |
80679 |
| XSRETURN(1); |
| 393 |
|
| |
| 394 |
|
| void |
| 395 |
|
| CLONE_SKIP(...) |
| 396 |
|
| CODE: |
| 397 |
0 |
| ST(0) = &PL_sv_yes; |
| 398 |
0 |
| XSRETURN(1); |