-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
condensed path impl checkpoint (wip)
- Loading branch information
Showing
14 changed files
with
613 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
skipledger-base/src/main/java/io/crums/sldg/CondensedRow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.