Skip to content

Commit

Permalink
added function to paima concise consume for ease of iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
mirtyl-wacdec authored and martin-tomko-vacuumlabs committed Dec 8, 2022
1 parent 2809c60 commit c55f2c8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
4 changes: 3 additions & 1 deletion paima-concise/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
build/
node_modules
*.tsbuildinfo
cache/
cache/
*.js
*.d.ts
17 changes: 10 additions & 7 deletions paima-concise/src/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,30 @@ const initialize = (input: string, version = EncodingVersion.V1): ConciseConsume
initialInput(_decompress = false): string {
return this.conciseInput;
},
nextValue(): ConciseValue | '' {
nextValue(): ConciseValue | null {
const [nextValue] = conciseValues.splice(0, 1);
return nextValue ?? '';
return nextValue ?? null;
},
popValue(): ConciseValue | '' {
remainingValues(): ConciseValue[] {
return this.conciseValues
},
popValue(): ConciseValue | null {
const nextValue = conciseValues.pop();
return nextValue ?? '';
return nextValue ?? null;
},
prefix(): string {
return this.concisePrefix;
},
readValue(position: number): ConciseValue | '' {
readValue(position: number): ConciseValue | null {
const index = position - 1;
return this.conciseValues[index] ?? '';
return this.conciseValues[index] ?? null;
},
stateIdentifiers(): ConciseValue[] {
return this.conciseValues.filter(value => value.isStateIdentifier);
},
valueCount(): number {
return this.conciseValues.length;
},
}
};
};

Expand Down
9 changes: 4 additions & 5 deletions paima-concise/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ export type ConciseConsumer = {
conciseInput: string;
concisePrefix: string;
conciseValues: ConciseValue[];

prefix: () => string;
stateIdentifiers: () => ConciseValue[];
nextValue: () => ConciseValue | '';

popValue: () => ConciseValue | '';
nextValue: () => ConciseValue | null;
remainingValues: () => ConciseValue[];
popValue: () => ConciseValue | null;
initialInput: (decompress?: boolean) => UTF8String;
// Positions start at 1
readValue: (position: number) => ConciseValue | '';
readValue: (position: number) => ConciseValue | null;
valueCount: () => number;
};

0 comments on commit c55f2c8

Please sign in to comment.