Skip to content

Commit c1ca4a5

Browse files
committed
Record and vector edits
1 parent 0cd78fe commit c1ca4a5

File tree

4 files changed

+65
-63
lines changed

4 files changed

+65
-63
lines changed

convex-core/src/main/java/convex/core/data/AVector.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public boolean print(BlobBuilder sb, long limit) {
124124
}
125125

126126
@Override
127-
public T get(int index) {
127+
public final T get(int index) {
128128
return get((long) index);
129129
}
130130

@@ -145,6 +145,14 @@ public <R extends ACell> AVector<R> flatMap(Function<? super T, ? extends ASeque
145145
}
146146
return result;
147147
}
148+
149+
@SuppressWarnings("unchecked")
150+
@Override
151+
protected <R> void copyToArray(R[] arr, int offset) {
152+
for (int i=0; i<count; i++) {
153+
arr[offset+i]=(R) get(i);
154+
}
155+
}
148156

149157
@Override
150158
public abstract AVector<T> concat(ASequence<? extends T> b);

convex-core/src/main/java/convex/core/data/DenseRecord.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public ACell get(Keyword key) {
8585

8686
@Override
8787
public RecordFormat getFormat() {
88-
// TODO Auto-generated method stub
88+
// No format defined for dense records
8989
return null;
9090
}
9191

@@ -97,19 +97,17 @@ public MapEntry<CVMLong, ACell> entryAt(long i) {
9797

9898
@Override
9999
public AVector<CVMLong> getKeys() {
100-
// TODO Auto-generated method stub
101-
return Vectors.range(0,count);
100+
// TODO: allow range access in DenseRecords?
101+
return null;
102102
}
103103

104104
@Override
105105
public Set<CVMLong> keySet() {
106-
// TODO Auto-generated method stub
107-
return null;
106+
return Sets.empty();
108107
}
109108

110109
@Override
111110
public ACell get(ACell key) {
112-
// TODO Auto-generated method stub
113111
return null;
114112
}
115113

convex-core/src/main/java/convex/core/data/VectorArray.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,16 +300,12 @@ public Ref<ACell> getRef(int i) {
300300
public AVector<T> dissocAt(long i) {
301301
int n=(int)count;
302302
if ((i<0)||(i>=n)) return null;
303+
if (i==0) return slice(1,count);
304+
if (i==n-1) return slice(0,i);
305+
303306
ACell[] cells=Arrays.copyOf(data, n-1);
304307
System.arraycopy(data, (int)(i+1), cells, (int)i, (int)(n-i-1));
305308

306309
return wrap(cells);
307310
}
308-
309-
310-
311-
312-
313-
314-
315311
}

convex-core/src/test/java/convex/test/generators/FormGen.java

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -27,56 +27,56 @@ public FormGen() {
2727
public ACell generate(SourceOfRandomness r, GenerationStatus status) {
2828
int type = r.nextInt(12);
2929
switch (type) {
30-
case 0:
31-
return null;
32-
33-
case 1:
34-
// Empty syntax with a nested form
35-
return Syntax.create(generate(r, status));
36-
37-
case 2:
38-
return Gen.PRIMITIVE.generate(r, status);
39-
case 3:
40-
return Gen.STRING.generate(r, status);
41-
42-
case 4:
43-
return Gen.NUMERIC.generate(r, status);
44-
45-
case 5: {
46-
// List of random forms
47-
List<ACell> subForms = this.times(r.nextInt(4)).generate(r, status);
48-
return Lists.create(subForms);
49-
}
50-
51-
case 6: {
52-
// random core symbol
53-
AHashMap<Symbol, ACell> env = Core.ENVIRONMENT;
54-
int n = (int) env.count();
55-
Symbol sym = env.entryAt(r.nextInt(n)).getKey();
56-
return sym;
57-
}
58-
59-
case 7: {
60-
// a vector of random subforms
61-
List<ACell> subForms = this.times(r.nextInt(4)).generate(r, status);
62-
return Vectors.create(subForms);
63-
}
64-
65-
case 8: {
66-
return Gen.SYNTAX.generate(r, status);
67-
}
68-
69-
case 9:
70-
return Gen.VALUE.generate(r, status);
30+
case 0:
31+
return null;
32+
33+
case 1:
34+
// Empty syntax with a nested form
35+
return Syntax.create(generate(r, status));
36+
37+
case 2:
38+
return Gen.PRIMITIVE.generate(r, status);
39+
case 3:
40+
return Gen.STRING.generate(r, status);
41+
42+
case 4:
43+
return Gen.NUMERIC.generate(r, status);
44+
45+
case 5: {
46+
// List of random forms
47+
List<ACell> subForms = this.times(r.nextInt(4)).generate(r, status);
48+
return Lists.create(subForms);
49+
}
50+
51+
case 6: {
52+
// random core symbol
53+
AHashMap<Symbol, ACell> env = Core.ENVIRONMENT;
54+
int n = (int) env.count();
55+
Symbol sym = env.entryAt(r.nextInt(n)).getKey();
56+
return sym;
57+
}
58+
59+
case 7: {
60+
// a vector of random subforms
61+
List<ACell> subForms = this.times(r.nextInt(4)).generate(r, status);
62+
return Vectors.create(subForms);
63+
}
7164

72-
default: {
73-
// random form containing core symbol at head
74-
List<ACell> subForms = this.times(r.nextInt(4)).generate(r, status);
75-
AHashMap<Symbol, ACell> env = Core.ENVIRONMENT;
76-
int n = (int) env.count();
77-
Symbol sym = env.entryAt(r.nextInt(n)).getKey();
78-
return RT.cons(sym, Lists.create(subForms));
79-
}
65+
case 8: {
66+
return Gen.SYNTAX.generate(r, status);
67+
}
68+
69+
case 9:
70+
return Gen.VALUE.generate(r, status);
71+
72+
default: {
73+
// random form containing a core symbol at head
74+
List<ACell> subForms = this.times(r.nextInt(4)).generate(r, status);
75+
AHashMap<Symbol, ACell> env = Core.ENVIRONMENT;
76+
int n = (int) env.count();
77+
Symbol sym = env.entryAt(r.nextInt(n)).getKey();
78+
return RT.cons(sym, Lists.create(subForms));
79+
}
8080
}
8181
}
8282
}

0 commit comments

Comments
 (0)