Skip to content

Commit

Permalink
Record and vector edits
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 22, 2024
1 parent 0cd78fe commit c1ca4a5
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 63 deletions.
10 changes: 9 additions & 1 deletion convex-core/src/main/java/convex/core/data/AVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public boolean print(BlobBuilder sb, long limit) {
}

@Override
public T get(int index) {
public final T get(int index) {
return get((long) index);
}

Expand All @@ -145,6 +145,14 @@ public <R extends ACell> AVector<R> flatMap(Function<? super T, ? extends ASeque
}
return result;
}

@SuppressWarnings("unchecked")
@Override
protected <R> void copyToArray(R[] arr, int offset) {
for (int i=0; i<count; i++) {
arr[offset+i]=(R) get(i);
}
}

@Override
public abstract AVector<T> concat(ASequence<? extends T> b);
Expand Down
10 changes: 4 additions & 6 deletions convex-core/src/main/java/convex/core/data/DenseRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public ACell get(Keyword key) {

@Override
public RecordFormat getFormat() {
// TODO Auto-generated method stub
// No format defined for dense records
return null;
}

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

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

@Override
public Set<CVMLong> keySet() {
// TODO Auto-generated method stub
return null;
return Sets.empty();
}

@Override
public ACell get(ACell key) {
// TODO Auto-generated method stub
return null;
}

Expand Down
10 changes: 3 additions & 7 deletions convex-core/src/main/java/convex/core/data/VectorArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,12 @@ public Ref<ACell> getRef(int i) {
public AVector<T> dissocAt(long i) {
int n=(int)count;
if ((i<0)||(i>=n)) return null;
if (i==0) return slice(1,count);
if (i==n-1) return slice(0,i);

ACell[] cells=Arrays.copyOf(data, n-1);
System.arraycopy(data, (int)(i+1), cells, (int)i, (int)(n-i-1));

return wrap(cells);
}







}
98 changes: 49 additions & 49 deletions convex-core/src/test/java/convex/test/generators/FormGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,56 +27,56 @@ public FormGen() {
public ACell generate(SourceOfRandomness r, GenerationStatus status) {
int type = r.nextInt(12);
switch (type) {
case 0:
return null;

case 1:
// Empty syntax with a nested form
return Syntax.create(generate(r, status));

case 2:
return Gen.PRIMITIVE.generate(r, status);
case 3:
return Gen.STRING.generate(r, status);

case 4:
return Gen.NUMERIC.generate(r, status);

case 5: {
// List of random forms
List<ACell> subForms = this.times(r.nextInt(4)).generate(r, status);
return Lists.create(subForms);
}

case 6: {
// random core symbol
AHashMap<Symbol, ACell> env = Core.ENVIRONMENT;
int n = (int) env.count();
Symbol sym = env.entryAt(r.nextInt(n)).getKey();
return sym;
}

case 7: {
// a vector of random subforms
List<ACell> subForms = this.times(r.nextInt(4)).generate(r, status);
return Vectors.create(subForms);
}

case 8: {
return Gen.SYNTAX.generate(r, status);
}

case 9:
return Gen.VALUE.generate(r, status);
case 0:
return null;

case 1:
// Empty syntax with a nested form
return Syntax.create(generate(r, status));

case 2:
return Gen.PRIMITIVE.generate(r, status);
case 3:
return Gen.STRING.generate(r, status);

case 4:
return Gen.NUMERIC.generate(r, status);

case 5: {
// List of random forms
List<ACell> subForms = this.times(r.nextInt(4)).generate(r, status);
return Lists.create(subForms);
}

case 6: {
// random core symbol
AHashMap<Symbol, ACell> env = Core.ENVIRONMENT;
int n = (int) env.count();
Symbol sym = env.entryAt(r.nextInt(n)).getKey();
return sym;
}

case 7: {
// a vector of random subforms
List<ACell> subForms = this.times(r.nextInt(4)).generate(r, status);
return Vectors.create(subForms);
}

default: {
// random form containing core symbol at head
List<ACell> subForms = this.times(r.nextInt(4)).generate(r, status);
AHashMap<Symbol, ACell> env = Core.ENVIRONMENT;
int n = (int) env.count();
Symbol sym = env.entryAt(r.nextInt(n)).getKey();
return RT.cons(sym, Lists.create(subForms));
}
case 8: {
return Gen.SYNTAX.generate(r, status);
}

case 9:
return Gen.VALUE.generate(r, status);

default: {
// random form containing a core symbol at head
List<ACell> subForms = this.times(r.nextInt(4)).generate(r, status);
AHashMap<Symbol, ACell> env = Core.ENVIRONMENT;
int n = (int) env.count();
Symbol sym = env.entryAt(r.nextInt(n)).getKey();
return RT.cons(sym, Lists.create(subForms));
}
}
}
}

0 comments on commit c1ca4a5

Please sign in to comment.