Skip to content

Commit

Permalink
Misc edits
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Jul 11, 2023
1 parent cb099a2 commit 0a69331
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
1 change: 0 additions & 1 deletion convex-core/src/main/java/convex/core/data/ACell.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ public <T extends ACell> T mark(Consumer<Ref<ACell>> noveltyHandler) {
return (T) this;
}


/**
* Creates a persisted Ref with the given value in the current store.
*
Expand Down
2 changes: 1 addition & 1 deletion convex-core/src/main/java/convex/core/data/BlobMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public boolean isCanonical() {
@SuppressWarnings("unchecked")
@Override
public BlobMap<K,V> updateRefs(IRefFunction func) {
MapEntry<K, V> newEntry = (entry == null) ? null : entry.updateRefs(func);
MapEntry<K, V> newEntry = Ref.update(entry,func);
Ref<BlobMap<K, V>>[] newChildren = Ref.updateRefs(children, func);
if ((entry == newEntry) && (children == newChildren)) return this;
BlobMap<K,V> result= new BlobMap<K, V>(depth, prefixLength, newEntry, (Ref[])newChildren, mask, count);
Expand Down
13 changes: 13 additions & 0 deletions convex-core/src/main/java/convex/core/data/Ref.java
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,19 @@ public static int mergeFlags(int a, int b) {
*/
public abstract Ref<T> ensureCanonical();

/**
* Updates Refs in an arbitrary Cell
* @param <T> Type of Cell
* @param o Cell to update
* @param func Ref update function
* @return Updated Cell (will be the same cell if Refs unchanged)
*/
@SuppressWarnings("unchecked")
public static <T extends ACell> T update(T o, IRefFunction func) {
if (o==null) return o;
return (T) o.updateRefs(func);
}

@SuppressWarnings("unchecked")
public static <R extends ACell> R updateRefs(R a, IRefFunction func) {
if (a==null) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public <R extends ACell> Ref<R> getRef(int i) {

@Override
public Invoke updateRefs(IRefFunction func) {
ACell newCommand = Utils.updateRefs(command, func);
ACell newCommand = Ref.update(command, func);
if (newCommand == command) return this;
return Invoke.create(origin,getSequence(), newCommand);
}
Expand Down
7 changes: 0 additions & 7 deletions convex-core/src/main/java/convex/core/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import convex.core.data.AVector;
import convex.core.data.Blob;
import convex.core.data.BlobBuilder;
import convex.core.data.IRefFunction;
import convex.core.data.Ref;
import convex.core.data.Vectors;
import convex.core.data.prim.CVMLong;
Expand Down Expand Up @@ -1171,12 +1170,6 @@ public static <R extends ACell> Ref<R> getRef(ACell o, int i) {
return o.getRef(i);
}

@SuppressWarnings("unchecked")
public static <T extends ACell> T updateRefs(T o, IRefFunction func) {
if (o==null) return o;
return (T) o.updateRefs(func);
}

public static int bitCount(short mask) {
return Integer.bitCount(mask & 0xFFFF);
}
Expand Down
10 changes: 5 additions & 5 deletions convex-core/src/test/java/convex/core/StateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public void testMultiCellTrip() throws BadFormatException {
// Hash of a known value in the tree that should be encoded
Hash check=Hash.fromHex("1fe0a93790d5e2a6d6d31db57edc611b128afe97941af611f65b703006ba5387");

Refs.visitAllRefs(s.getRef(), r->{
if (r.getHash().equals(check)) {
System.out.println(r.getValue());
}
});
//Refs.visitAllRefs(s.getRef(), r->{
// if (r.getHash().equals(check)) {
// System.out.println(r.getValue());
// }
//});

Blob b=Format.encodeMultiCell(s);

Expand Down

0 comments on commit 0a69331

Please sign in to comment.