Skip to content

Commit

Permalink
condensed path impl checkpoint (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnahraf committed Jun 14, 2024
1 parent 2c3252e commit a14a461
Show file tree
Hide file tree
Showing 14 changed files with 613 additions and 173 deletions.
16 changes: 8 additions & 8 deletions skipledger-base/pathpack_format.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ The components of the structure are first defined, and the final object `PATH_PA


TYPE := BYTE // 0 means full; 1 means condensed
RS_COUNT := INT // stitch row number count
STITCH_RNS := LONG ^RS_COUNT // stitch row numbers in strictly ascending order
SR_COUNT := INT // stitch row no. count
STITCH_RNS := LONG ^SR_COUNT // stitch row no.s in strictly ascending order

I_COUNT := INT // number of rows with full info (have input hash)
// inferred from SkipLedger#stitch(..)
// The full row no.s themselves (I_COUNT -many of them)
// are also known at this point.
I_COUNT := INT // no. of rows in the path (have input hashes)
// The path's row no.s are inferred from
// SkipLedger#stitch(STITCH_RNS)
// I_COUNT is the size of that list

R_COUNT := INT // number of rows with only ref-hashes inferred from
R_COUNT := INT // no. of rows with only ref-hashes inferred from
// depending on type, the size of:
//
// TYPE [0] (full)
Expand Down Expand Up @@ -71,6 +71,6 @@ The components of the structure are first defined, and the final object `PATH_PA
// In this way, fs the byte-size of the funnel
// block is determined from the STITCH_RNS.

PATH_PACK := TYPE RS_COUNT STITCH_RNS R_TBL I_TBL [FUNNELS]
PATH_PACK := SR_COUNT STITCH_RNS TYPE R_TBL I_TBL [FUNNELS]


25 changes: 12 additions & 13 deletions skipledger-base/src/main/java/io/crums/sldg/BaggedRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package io.crums.sldg;

import java.nio.ByteBuffer;
import java.util.Objects;

/**
* Row backed by data in a {@linkplain RowBag}.
Expand All @@ -14,35 +13,35 @@
*/
public class BaggedRow extends Row {

private final long rowNumber;
private final long rowNo;
private final LevelsPointer levelsPtr;

private final RowBag bag;

/**
* Constructor does not validate that the bag indeed has the necessary data.
* In order to create a subclass that does validate, invoke {@linkplain #hash()}
* in the constructor.
*/
public BaggedRow(long rowNumber, RowBag bag) {
this.rowNumber = rowNumber;
this.bag = Objects.requireNonNull(bag, "null bag");
SkipLedger.checkRealRowNumber(rowNumber);
public BaggedRow(long rowNo, RowBag bag) {
this.rowNo = rowNo;
this.levelsPtr = bag.levelsPointer(rowNo);
this.bag = bag;
}


@Override
public LevelsPointer levelsPointer() {
return bag.levelsPointer(rowNumber);
return levelsPtr;
}

// @Override
// public final long no() {
// return rowNumber;
// }

@Override
public ByteBuffer inputHash() {
return bag.inputHash(rowNumber);
return bag.inputHash(rowNo);
}




}

66 changes: 66 additions & 0 deletions skipledger-base/src/main/java/io/crums/sldg/CondensedRow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2024 Babak Farhang
*/
package io.crums.sldg;

import static io.crums.sldg.SkipLedger.levelLinked;

import java.nio.ByteBuffer;

/**
*
*/
public class CondensedRow extends Row {


public static Row compressToLevelRowNo(Row row, long levelRn) {

int level = levelLinked(levelRn, row.no());
if (level < 0)
throw new IllegalArgumentException(
"levelRn " + levelRn + " not covered by row " + row);

if (row.levelsPointer().coversLevel(level))
return row.isCompressed() ?
row : new CondensedRow(row, level, true);

throw new IllegalArgumentException(
"levelRn " + levelRn + " not covered by row " + row.levelsPointer());
}





private final Row row;

private final int refLevel;


private CondensedRow(Row row, int level, boolean trustMe) {
this.row = row;
this.refLevel = level;
}

public CondensedRow(Row row, int level) {
this(row, level, true);

LevelsPointer levelsPtr = row.levelsPointer();
if (!levelsPtr.coversLevel(level))
throw new IllegalArgumentException(
"level " + level + " not covered: " + levelsPtr);
}


@Override
public LevelsPointer levelsPointer() {
return row.levelsPointer().compressToLevel(refLevel);
}

@Override
public ByteBuffer inputHash() {
return row.inputHash();
}


}
Loading

0 comments on commit a14a461

Please sign in to comment.