Comparing version 0.0.14 to 0.0.15
@@ -13,2 +13,19 @@ import * as env from "./env"; | ||
export const UNKNOWN_PRIMARY_KEY: u64 = 0xffffffffffffffff | ||
export class PrimaryIterator { | ||
constructor( | ||
public i: i32, | ||
public primary: u64, | ||
) {} | ||
isOk(): bool { | ||
return this.i >= 0; | ||
} | ||
isEnd(): bool { | ||
return this.i == -2; | ||
} | ||
} | ||
export class DBI64 { | ||
@@ -21,11 +38,12 @@ constructor( | ||
store(id: u64, data: u8[], payer: u64): i32 { | ||
store(id: u64, data: u8[], payer: u64): PrimaryIterator { | ||
let data_ptr = data.dataStart; | ||
return env.db_store_i64(this.scope, this.table, payer, id, data_ptr, data.length ); | ||
let i = env.db_store_i64(this.scope, this.table, payer, id, data_ptr, data.length ); | ||
return new PrimaryIterator(i, id); | ||
} | ||
// export declare function db_update_i64(iterator: i32, payer: u64, data: usize, len: usize): void | ||
update(iterator: i32, payer: u64, data: u8[]): void { | ||
update(iterator: PrimaryIterator, payer: u64, data: u8[]): void { | ||
let data_ptr = data.dataStart; | ||
env.db_update_i64(iterator, payer, data_ptr, data.length); | ||
env.db_update_i64(iterator.i, payer, data_ptr, data.length); | ||
} | ||
@@ -39,4 +57,4 @@ | ||
// export declare function db_get_i64(iterator: i32, data: usize, len: usize): i32 | ||
get(iterator: i32): u8[] { | ||
let size = env.db_get_i64(iterator, 0, 0); | ||
get(iterator: PrimaryIterator): u8[] { | ||
let size = env.db_get_i64(iterator.i, 0, 0); | ||
if (size == 0) { | ||
@@ -47,3 +65,3 @@ return []; | ||
let ptr = arr.dataStart; | ||
env.db_get_i64(iterator, ptr, size); | ||
env.db_get_i64(iterator.i, ptr, size); | ||
return arr; | ||
@@ -53,35 +71,42 @@ } | ||
// export declare function db_next_i64(iterator: i32, primary_ptr: usize): i32 | ||
next(iterator: i32): i32 { | ||
next(iterator: i32): PrimaryIterator { | ||
let primary_ptr = __alloc(sizeof<u64>()); | ||
let itNext = env.db_next_i64(iterator, primary_ptr); | ||
return itNext; | ||
return new PrimaryIterator(itNext, load<u64>(primary_ptr)); | ||
} | ||
// export declare function db_previous_i64(iterator: i32, primary_ptr: usize): i32 | ||
previous(iterator: i32): i32 { | ||
previous(iterator: i32): PrimaryIterator { | ||
let primary_ptr = __alloc(sizeof<u64>()); | ||
let itNext = env.db_previous_i64(iterator, primary_ptr); | ||
return itNext; | ||
return new PrimaryIterator(itNext, load<u64>(primary_ptr)); | ||
} | ||
// export declare function db_find_i64(code: u64, scope: u64, table: u64, id: u64): i32 | ||
find(id: u64): i32 { | ||
return env.db_find_i64(this.code, this.scope, this.table, id); | ||
find(id: u64): PrimaryIterator { | ||
let i = env.db_find_i64(this.code, this.scope, this.table, id); | ||
if (i >= 0) { | ||
return new PrimaryIterator(i, id); | ||
} | ||
return new PrimaryIterator(i, id); | ||
} | ||
// export declare function db_lowerbound_i64(code: u64, scope: u64, table: u64, id: u64): i32 | ||
lowerBound(id: u64): i32 { | ||
return env.db_lowerbound_i64(this.code, this.scope, this.table, id); | ||
lowerBound(id: u64): PrimaryIterator { | ||
let i = env.db_lowerbound_i64(this.code, this.scope, this.table, id); | ||
return new PrimaryIterator(i, UNKNOWN_PRIMARY_KEY); | ||
} | ||
// export declare function db_upperbound_i64(code: u64, scope: u64, table: u64, id: u64): i32 | ||
upperBound(id: u64): i32 { | ||
return env.db_upperbound_i64(this.code, this.scope, this.table, id); | ||
upperBound(id: u64): PrimaryIterator { | ||
let i = env.db_upperbound_i64(this.code, this.scope, this.table, id); | ||
return new PrimaryIterator(i, UNKNOWN_PRIMARY_KEY); | ||
} | ||
// export declare function db_end_i64(code: u64, scope: u64, table: u64): i32 | ||
end(): i32 { | ||
return env.db_end_i64(this.code, this.scope, this.table); | ||
end(): PrimaryIterator { | ||
let i = env.db_end_i64(this.code, this.scope, this.table); | ||
return new PrimaryIterator(i, UNKNOWN_PRIMARY_KEY); | ||
} | ||
} | ||
@@ -86,8 +86,8 @@ export declare function memcpy (destination: usize, source: usize, num: usize): usize; | ||
export declare function db_idx_long_double_remove(iterator: i32): void | ||
export declare function db_idx_long_double_next(iterator: i32, primary_ptr: u64): i32 | ||
export declare function db_idx_long_double_previous(iterator: i32, primary_ptr: u64): i32 | ||
export declare function db_idx_long_double_next(iterator: i32, primary_ptr: usize): i32 | ||
export declare function db_idx_long_double_previous(iterator: i32, primary_ptr: usize): i32 | ||
export declare function db_idx_long_double_find_primary(code: u64, scope: u64, table: u64, secondary_ptr: usize, primary: u64): i32 | ||
export declare function db_idx_long_double_find_secondary(code: u64, scope: u64, table: u64, secondary_ptr: usize, primary_ptr: u64): i32 | ||
export declare function db_idx_long_double_lowerbound(code: u64, scope: u64, table: u64, secondary_ptr: usize, primary_ptr: u64): i32 | ||
export declare function db_idx_long_double_upperbound(code: u64, scope: u64, table: u64, secondary_ptr: usize, primary_ptr: u64): i32 | ||
export declare function db_idx_long_double_find_secondary(code: u64, scope: u64, table: u64, secondary_ptr: usize, primary_ptr: usize): i32 | ||
export declare function db_idx_long_double_lowerbound(code: u64, scope: u64, table: u64, secondary_ptr: usize, primary_ptr: usize): i32 | ||
export declare function db_idx_long_double_upperbound(code: u64, scope: u64, table: u64, secondary_ptr: usize, primary_ptr: usize): i32 | ||
export declare function db_idx_long_double_end(code: u64, scope: u64, table: u64): i32; | ||
@@ -94,0 +94,0 @@ |
@@ -93,7 +93,12 @@ import { IDXDB, SecondaryValue, SecondaryType, SecondaryIterator, SecondaryReturnValue } from "./idxdb"; | ||
let primary_ptr = __alloc(sizeof<u64>()); | ||
let secondary_ptr = __alloc(sizeof<u64>()*2); | ||
store<u64>(secondary_ptr, secondary.lo); | ||
store<u64>(secondary_ptr+8, secondary.hi); | ||
let it = env.db_idx128_find_secondary(this.code, this.scope, this.table, secondary_ptr, primary_ptr); | ||
return new SecondaryIterator(it, load<u64>(primary_ptr), this.dbIndex); | ||
let secondaryCopy = new Array<u64>(2); | ||
secondaryCopy[0] = secondary.lo; | ||
secondaryCopy[1] = secondary.hi; | ||
let secondary_ptr = secondaryCopy.dataStart; | ||
let it = env.db_idx128_lowerbound(this.code, this.scope, this.table, secondary_ptr, primary_ptr); | ||
if (secondary.lo == secondaryCopy[0] && secondary.hi == secondaryCopy[1]) { | ||
return new SecondaryIterator(it, load<u64>(primary_ptr), this.dbIndex); | ||
} else { | ||
return new SecondaryIterator(-1, 0, this.dbIndex); | ||
} | ||
} | ||
@@ -100,0 +105,0 @@ |
@@ -93,9 +93,19 @@ import { IDXDB, SecondaryValue, SecondaryType, SecondaryIterator, SecondaryReturnValue } from "./idxdb"; | ||
let primary_ptr = __alloc(sizeof<u64>()); | ||
let secondary_ptr = __alloc(sizeof<u64>()*4); | ||
store<u64>(secondary_ptr, secondary.lo1); | ||
store<u64>(secondary_ptr + 8, secondary.lo2); | ||
store<u64>(secondary_ptr + 16, secondary.hi1); | ||
store<u64>(secondary_ptr + 24, secondary.hi2); | ||
let it = env.db_idx256_find_secondary(this.code, this.scope, this.table, secondary_ptr, 2, primary_ptr); | ||
return new SecondaryIterator(it, load<u64>(primary_ptr), this.dbIndex); | ||
let secondaryCopy = new Array<u64>(4); | ||
secondaryCopy[0] = secondary.lo1; | ||
secondaryCopy[1] = secondary.lo2; | ||
secondaryCopy[2] = secondary.hi1; | ||
secondaryCopy[3] = secondary.hi2; | ||
let it = env.db_idx256_lowerbound(this.code, this.scope, this.table, secondaryCopy.dataStart, 2, primary_ptr); | ||
if ( | ||
secondaryCopy[0] == secondary.lo1 && | ||
secondaryCopy[1] == secondary.lo2 && | ||
secondaryCopy[2] == secondary.hi1 && | ||
secondaryCopy[3] == secondary.hi2 | ||
) { | ||
return new SecondaryIterator(it, load<u64>(primary_ptr), this.dbIndex); | ||
} else { | ||
return new SecondaryIterator(-1, 0, this.dbIndex); | ||
} | ||
} | ||
@@ -102,0 +112,0 @@ |
@@ -76,4 +76,9 @@ import {IDXDB, SecondaryValue, SecondaryType, SecondaryIterator, SecondaryReturnValue} from "./idxdb"; | ||
store<u64>(secondary_ptr, secondary); | ||
let it = env.db_idx64_find_secondary(this.code, this.scope, this.table, secondary_ptr, primary_ptr); | ||
return new SecondaryIterator(it, load<u64>(primary_ptr), this.dbIndex); | ||
let it = env.db_idx64_lowerbound(this.code, this.scope, this.table, secondary_ptr, primary_ptr); | ||
let secondary2 = load<u64>(secondary_ptr); | ||
if (secondary2 == secondary) { | ||
return new SecondaryIterator(it, load<u64>(primary_ptr), this.dbIndex); | ||
} else { | ||
return new SecondaryIterator(-1, 0, this.dbIndex); | ||
} | ||
} | ||
@@ -80,0 +85,0 @@ |
@@ -83,7 +83,30 @@ import {IDXDB, SecondaryValue, SecondaryType, SecondaryIterator, SecondaryReturnValue} from "./idxdb"; | ||
let primary_ptr = __alloc(sizeof<u64>()); | ||
let it = env.db_idx_long_double_find_secondary(this.code, this.scope, this.table, secondary.data.dataStart, primary_ptr); | ||
let secondaryCopy = new Array<u64>(2); | ||
secondaryCopy[0] = secondary.data[0]; | ||
secondaryCopy[1] = secondary.data[1]; | ||
let secondary_ptr = secondaryCopy.dataStart; | ||
let it = env.db_idx_long_double_lowerbound(this.code, this.scope, this.table, secondary_ptr, primary_ptr); | ||
if (secondary.data[0] == secondaryCopy[0] && secondary.data[1] == secondaryCopy[1]) { | ||
return new SecondaryIterator(it, load<u64>(primary_ptr), this.dbIndex); | ||
} else { | ||
return new SecondaryIterator(-1, 0, this.dbIndex); | ||
} | ||
} | ||
lowerBound(secondary: Float128): SecondaryIterator { | ||
let primary_ptr = __alloc(sizeof<u64>()); | ||
let secondaryCopy = new Array<u64>(2); | ||
secondaryCopy[0] = secondary.data[0]; | ||
secondaryCopy[1] = secondary.data[1]; | ||
let secondary_ptr = secondaryCopy.dataStart; | ||
let it = env.db_idx_long_double_lowerbound(this.code, this.scope, this.table, secondary_ptr, primary_ptr); | ||
return new SecondaryIterator(it, load<u64>(primary_ptr), this.dbIndex); | ||
} | ||
lowerbound(secondary: SecondaryValue): SecondaryReturnValue { | ||
lowerBoundEx(secondary: SecondaryValue): SecondaryReturnValue { | ||
check(secondary.type == SecondaryType.F128, "idx_long_double: bad secondary type"); | ||
@@ -106,3 +129,15 @@ check(secondary.value.length == 2, "idx_long_double: bad value"); | ||
upperbound(secondary: SecondaryValue): SecondaryReturnValue { | ||
upperBound(secondary: Float128): SecondaryIterator { | ||
let primary_ptr = __alloc(sizeof<u64>()); | ||
let secondaryCopy = new Array<u64>(2); | ||
secondaryCopy[0] = secondary.data[0]; | ||
secondaryCopy[1] = secondary.data[1]; | ||
let secondary_ptr = secondaryCopy.dataStart; | ||
let it = env.db_idx_long_double_upperbound(this.code, this.scope, this.table, secondary_ptr, primary_ptr); | ||
return new SecondaryIterator(it, load<u64>(primary_ptr), this.dbIndex); | ||
} | ||
upperBoundEx(secondary: SecondaryValue): SecondaryReturnValue { | ||
check(secondary.type == SecondaryType.F128, "idx_long_double: bad secondary type"); | ||
@@ -109,0 +144,0 @@ check(secondary.value.length == 2, "idx_long_double: bad value"); |
@@ -75,4 +75,9 @@ import {IDXDB, SecondaryValue, SecondaryType, SecondaryIterator, SecondaryReturnValue} from "./idxdb"; | ||
store<f64>(secondary_ptr, secondary); | ||
let it = env.db_idx_double_find_secondary(this.code, this.scope, this.table, secondary_ptr, primary_ptr); | ||
return new SecondaryIterator(it, load<u64>(primary_ptr), this.dbIndex); | ||
let it = env.db_idx_double_lowerbound(this.code, this.scope, this.table, secondary_ptr, primary_ptr); | ||
let secondary2 = load<f64>(secondary_ptr); | ||
if (secondary2 == secondary) { | ||
return new SecondaryIterator(it, load<u64>(primary_ptr), this.dbIndex); | ||
} else { | ||
return new SecondaryIterator(-1, 0, this.dbIndex); | ||
} | ||
} | ||
@@ -79,0 +84,0 @@ |
@@ -6,3 +6,3 @@ export { U128, U256 } from "./bignum"; | ||
export { DBI64 } from "./dbi64"; | ||
export { DBI64, PrimaryIterator, UNKNOWN_PRIMARY_KEY } from "./dbi64"; | ||
export { IDX64 } from "./idx64"; | ||
@@ -59,3 +59,3 @@ export { IDXF64 } from "./idxf64"; | ||
export { PrimaryIterator, MultiIndex, MultiIndexValue, SAME_PAYER } from "./mi"; | ||
export { MultiIndex, MultiIndexValue, SAME_PAYER } from "./mi"; | ||
export { Singleton } from "./singleton"; | ||
@@ -62,0 +62,0 @@ |
import { IDXDB, SecondaryValue, SecondaryIterator } from "./idxdb"; | ||
import { DBI64, PrimaryValue } from "./dbi64"; | ||
import { DBI64, PrimaryIterator, PrimaryValue, UNKNOWN_PRIMARY_KEY } from "./dbi64"; | ||
import { Name } from "./name"; | ||
import { check } from "./system"; | ||
import { print } from "./debug"; | ||
@@ -12,14 +11,2 @@ export const SAME_PAYER = new Name(); | ||
export class PrimaryIterator { | ||
constructor(public i: i32) {} | ||
isOk(): bool { | ||
return this.i >= 0; | ||
} | ||
isEnd(): bool { | ||
return this.i == noAvailablePrimaryKey; | ||
} | ||
} | ||
export interface MultiIndexValue extends PrimaryValue { | ||
@@ -61,8 +48,16 @@ getSecondaryValue(index: usize): SecondaryValue; | ||
return new PrimaryIterator(it); | ||
return it; | ||
} | ||
update(it: PrimaryIterator, value: T, payer: Name): void { | ||
this.db.update(it.i, payer.N, value.pack()); | ||
let primary = value.getPrimaryValue(); | ||
if (it.primary == UNKNOWN_PRIMARY_KEY) { | ||
let it2 = this.db.find(primary); | ||
check(it2.i == it.i, "primary key can't be changed during update!"); | ||
it.primary = primary; | ||
} else { | ||
check(primary == it.primary, "primary key can't be changed during update!"); | ||
} | ||
this.db.update(it, payer.N, value.pack()); | ||
for (let i=0; i<this.idxdbs.length; i++) { | ||
@@ -94,2 +89,3 @@ let ret = this.idxdbs[i].findPrimaryEx(primary); | ||
let ret = this.idxdbs[i].findPrimaryEx(primary); | ||
check(ret.i.isOk(), "is not ok"); | ||
if (ret.i.isOk()) { | ||
@@ -102,3 +98,3 @@ this.idxdbs[i].remove(ret.i); | ||
get(iterator: PrimaryIterator): T { | ||
let data = this.db.get(iterator.i); | ||
let data = this.db.get(iterator); | ||
let ret = instantiate<T>(); | ||
@@ -115,3 +111,3 @@ ret.unpack(data); | ||
let data = this.db.get(iterator.i); | ||
let data = this.db.get(iterator); | ||
let ret = instantiate<T>(); | ||
@@ -123,14 +119,11 @@ ret.unpack(data); | ||
next(iterator: PrimaryIterator): PrimaryIterator { | ||
let i = this.db.next(iterator.i); | ||
return new PrimaryIterator(i); | ||
return this.db.next(iterator.i); | ||
} | ||
previous(iterator: PrimaryIterator): PrimaryIterator { | ||
let i = this.db.previous(iterator.i); | ||
return new PrimaryIterator(i); | ||
return this.db.previous(iterator.i); | ||
} | ||
find(id: u64): PrimaryIterator { | ||
let i = this.db.find(id); | ||
return new PrimaryIterator(i); | ||
return this.db.find(id); | ||
} | ||
@@ -151,9 +144,7 @@ | ||
lowerBound(id: u64): PrimaryIterator { | ||
let i = this.db.lowerBound(id); | ||
return new PrimaryIterator(i); | ||
return this.db.lowerBound(id); | ||
} | ||
upperBound(id: u64): PrimaryIterator { | ||
let i = this.db.upperBound(id); | ||
return new PrimaryIterator(i); | ||
return this.db.upperBound(id); | ||
} | ||
@@ -166,4 +157,3 @@ | ||
end(): PrimaryIterator { | ||
let i = this.db.end(); | ||
return new PrimaryIterator(i); | ||
return this.db.end(); | ||
} | ||
@@ -182,3 +172,3 @@ | ||
value.setSecondaryValue(it.dbIndex, idxValue); | ||
this.update(primaryIt, value, payer); | ||
this.db.update(primaryIt, payer.N, value.pack()); | ||
this.idxdbs[it.dbIndex].updateEx(it, idxValue, payer.N); | ||
@@ -185,0 +175,0 @@ } |
{ | ||
"name": "as-chain", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "chain module for assemblyscript", | ||
@@ -5,0 +5,0 @@ "main": "js/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
127653
3342