本文整理匯總了TypeScript中neuroglancer/util/uint64.Uint64.toString方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Uint64.toString方法的具體用法?TypeScript Uint64.toString怎麽用?TypeScript Uint64.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類neuroglancer/util/uint64.Uint64
的用法示例。
在下文中一共展示了Uint64.toString方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('HashSetUint64', () => {
let ht = new HashSetUint64();
let set = new Set<string>();
function compareViaIterate() {
let htValues = new Set<string>();
for (let v of ht) {
let s = v.toString();
expect(htValues.has(s)).toBe(false, `Duplicate key in hash table: ${s}`);
expect(set.has(s)).toBe(true, `Unexpected key ${s} in hash table`);
htValues.add(s);
}
for (let s of set) {
expect(htValues.has(s)).toBe(true, `Hash table is missing key ${s}`);
}
}
function compareViaHas() {
for (let s of set) {
let k = Uint64.parseString(s);
expect(ht.has(k)).toBe(true, `Hash table is missing key ${s}`);
}
}
function compare() {
compareViaIterate();
compareViaHas();
}
let numInsertions = 100;
function testInsert(k: Uint64) {
let s = '' + k;
set.add(s);
expect(ht.has(k)).toBe(false, `Unexpected positive has result for ${[k.low, k.high]}`);
ht.add(k);
compare();
}
let empty0 = new Uint64(ht.emptyLow, ht.emptyHigh);
testInsert(empty0);
for (let i = 0; i < numInsertions; ++i) {
let k: Uint64;
let s: string;
while (true) {
k = Uint64.random();
s = k.toString();
if (!set.has(s)) {
break;
}
}
testInsert(k);
}
let empty1 = new Uint64(ht.emptyLow, ht.emptyHigh);
testInsert(empty1);
});
示例2: compareViaIterate
function compareViaIterate() {
let htValues = new Map();
for (let [low, high] of ht) {
let v = new Uint64(low, high);
let s = v.toString();
if (htValues.has(s)) {
throw new Error('Duplicate key in hash table: ' + [low, high]);
}
if (!map.has(s)) {
throw new Error('Unexpected key ' + [low, high] + ' in hash table');
}
htValues.set(s, v);
}
for (let [s, k] of map) {
if (!htValues.has(s)) {
throw new Error('Hash table is missing key ' + [k.low, k.high]);
}
}
}
示例3: it
it('toString parseString round trip', () => {
function check(x: Uint64, base: number) {
let s = x.toString(base);
let y = Uint64.parseString(s, base);
expect(y.low).toBe(x.low, `s=${s}, x.low=${x.low}, x.high=${x.high}, y.low=${y.low}, y.high=${y.high}, base=${base}`);
expect(y.high).toBe(x.high, `s=${s}, x.low=${x.low}, x.high=${x.high}, y.low=${y.low}, y.high=${y.high}, base=${base}`);
}
const count = 100;
{
const u = new Uint64(264762631, 2836123747);
expect(u.toString(13)).toEqual('153c9125c642b111b8');
check(u, 13);
}
for (let base = 2; base <= 36; ++base) {
for (let i = 0; i < count; ++i) {
check(Uint64.random(), base);
}
}
});
示例4: check
function check(x: Uint64, base: number) {
let s = x.toString(base);
let y = Uint64.parseString(s, base);
expect(y.low).toBe(x.low);
expect(y.high).toBe(x.high);
}
示例5: it
it('test', () => {
let ht = new HashTable();
let map = new Map();
let maxValue = Math.pow(2, 32);
function genNumber() { return Math.floor(Math.random() * maxValue); }
function getRandomKey() {
while (true) {
let v = new Uint64(genNumber(), genNumber());
if (v.low !== ht.emptyLow || v.high !== ht.emptyHigh) {
return v;
}
}
}
function compareViaIterate() {
let htValues = new Map();
for (let [low, high] of ht) {
let v = new Uint64(low, high);
let s = v.toString();
if (htValues.has(s)) {
throw new Error('Duplicate key in hash table: ' + [low, high]);
}
if (!map.has(s)) {
throw new Error('Unexpected key ' + [low, high] + ' in hash table');
}
htValues.set(s, v);
}
for (let [s, k] of map) {
if (!htValues.has(s)) {
throw new Error('Hash table is missing key ' + [k.low, k.high]);
}
}
}
function compareViaHas() {
for (let [, k] of map) {
expect(ht.has(k.low, k.high)).toBe(true, `Hash table is missing key ${[k.low, k.high]}`);
}
}
function compare() {
compareViaIterate();
compareViaHas();
}
let numInsertions = 100;
for (let i = 0; i < numInsertions; ++i) {
let k: Uint64;
let s: string;
while (true) {
k = getRandomKey();
s = k.toString();
if (!map.has(k)) {
break;
}
}
map.set(s, k);
expect(ht.has(k.low, k.high))
.toBe(false, `Unexpected positive has result for ${[k.low, k.high]}`);
ht.add(k.low, k.high);
compare();
}
});
示例6: check
function check(x: Uint64, base: number) {
let s = x.toString(base);
let y = Uint64.parseString(s, base);
expect(y.low).toBe(x.low, `s=${s}, x.low=${x.low}, x.high=${x.high}, y.low=${y.low}, y.high=${y.high}, base=${base}`);
expect(y.high).toBe(x.high, `s=${s}, x.low=${x.low}, x.high=${x.high}, y.low=${y.low}, y.high=${y.high}, base=${base}`);
}