growth of mutable lists
@DanGrayson is already working on this.
Since Jul 27, 2017.
- Dominant language
- Macaulay2
- Stars
- 435
- Forks
- 297
- Avg merge
- 4d 20h
- Merged PRs (30d)
- 11
Description
It looks like mutable lists grow their length by only one at a time. Perhaps
the length should double when it needs to increase. Or just warn users to
amortize the cost themselves.
```
i36 : x = new MutableList
o36 = MutableList{}
o36 : MutableList
i37 : x#4=1
o37 = 1
i38 : peek x
o38 = MutableList{null, null, null, null, 1}
i39 : x#5=1
o39 = 1
i40 : peek x
o40 = MutableList{null, null, null, null, 1, 1}
```
from evaluate.d:
```
assignvector(m:List,i:Code,rhs:Code):Expr := (
x := m.v;
ival := eval(i);
when ival
is j:ZZcell do (
if isInt(j)
then (
k := toInt(j);
if k < 0 then k = k + length(x);
if k < 0 then return printErrorMessageE(i,"negative subscript out of bounds 0 .. "+tostring(length(x)-1));
val := eval(rhs);
when val is Error do return val else (
if k >= length(x) then (
x = new Sequence len k+1 do (
foreach t in x do provide t;
while true do provide nullE;
);
m.v = x; );
x.k = val;
val))
else printErrorMessageE(i,"expected small integer"))
is Error do ival
else printErrorMessageE(i,"index not an integer")
);
```
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.