-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from you21979/typescript-pr
typescript rewrite
- Loading branch information
Showing
10 changed files
with
308 additions
and
241 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
built | ||
doc | ||
Gulpfile.ts | ||
internal | ||
issue_template.md | ||
jenkins.sh | ||
lib/README.md | ||
lib/enu | ||
netci.groovy | ||
pull_request_template.md | ||
scripts | ||
src | ||
tests | ||
tslint.json | ||
Jakefile.js | ||
.editorconfig | ||
.gitattributes | ||
.gitmodules | ||
.settings/ | ||
.travis.yml | ||
.circleci | ||
.vscode/ | ||
.parallelperf.json | ||
test.config | ||
package-lock.json | ||
yarn.lock |
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { BinaryArray } from './lib/binaryarray' | ||
export = BinaryArray | ||
|
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,118 @@ | ||
import assert = require('assert'); | ||
import util = require('./util'); | ||
|
||
export class BinaryArray{ | ||
maxnum: number; | ||
storage: Uint32Array; | ||
constructor(maxnum : number){ | ||
this.maxnum = maxnum | ||
this.storage = util.createArray(util.getArraySize(maxnum), 0) | ||
} | ||
bitOn(no : number) : BinaryArray{ | ||
assert(this.maxnum > no, 'on:over flagmax'); | ||
const idx = util.getArrayIndex(no); | ||
assert(idx >= 0 && idx < this.storage.length, 'on:over idx range'); | ||
const pos = util.getFlagPos(no); | ||
const flag = 1 << pos; | ||
this.storage[idx] |= flag; | ||
return this; | ||
} | ||
bitOff(no : number) : BinaryArray{ | ||
assert(this.maxnum > no, 'off:over flagmax'); | ||
const idx = util.getArrayIndex(no); | ||
assert(idx >= 0 && idx < this.storage.length, 'off:over idx range'); | ||
const pos = util.getFlagPos(no); | ||
const flag = 1 << pos; | ||
if(this.storage[idx] & flag){ | ||
this.storage[idx] ^= flag; | ||
} | ||
return this; | ||
} | ||
at(no : number) : number{ | ||
assert(this.maxnum > no, 'get:over flagmax'); | ||
const idx = util.getArrayIndex(no); | ||
assert(idx >= 0 && idx < this.storage.length, 'is:over idx range'); | ||
const pos = util.getFlagPos(no); | ||
const flag = 1 << pos; | ||
return this.storage[idx] & flag ? 1 : 0; | ||
} | ||
toArray() : Array<number>{ | ||
const w = []; | ||
const max = this.maxnum; | ||
for(let i = 0; i < max; ++i ){ | ||
w.push(this.at(i)); | ||
} | ||
return w; | ||
} | ||
serialize(spec : Object) : Array<string>{ | ||
assert(spec instanceof Object, 'spec is must be Object') | ||
const w = this.toArray(); | ||
return Object.keys(spec) | ||
.filter((k) => w[spec[k]]) | ||
.map((k) => k) | ||
} | ||
toJSON() : string{ | ||
return JSON.stringify(this.toArray()) | ||
} | ||
isRange(no : number) : boolean{ | ||
if(!(this.maxnum > no)){ | ||
return false; | ||
} | ||
const idx = util.getArrayIndex(no); | ||
if(!(idx >= 0 && idx < this.storage.length)){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
rangeOf(xs : any) : Object{ | ||
if(!(xs instanceof Array)){ | ||
xs = [xs]; | ||
} | ||
return xs.reduce((r, v) => { | ||
r[v] = this.at(v) | ||
return r; | ||
}, {}) | ||
} | ||
check(on_list : Array<number>, off_list : Array<number> = []) : boolean{ | ||
const on = this.rangeOf(on_list); | ||
const off = this.rangeOf(off_list); | ||
const x = Object.keys(on).reduce((r, v) => { return r & on[v] }, 1) | ||
const y = Object.keys(off).reduce((r, v) => { return r & ~off[v] }, 1) | ||
return (x & y) ? true : false | ||
} | ||
toHexString() : string{ | ||
let str = ''; | ||
const n = this.storage.length; | ||
for(let i=n-1;i>=0;--i){ | ||
str = str + util.NumberToHexString(this.storage[i], 8); | ||
} | ||
return str; | ||
} | ||
static loadFromHexString(maxnum : number, str : string) : BinaryArray{ | ||
const ba = new BinaryArray(maxnum); | ||
const s = 8; | ||
let b = str.length - s; | ||
let e = str.length - 0; | ||
const n = str.length / s; | ||
for(let i = 0; i < n; ++i){ | ||
ba.storage[i] = parseInt(str.substring(b,e), 16); | ||
b -= s; | ||
e -= s; | ||
} | ||
return ba; | ||
} | ||
static loadFromArray(xs : Array<number>) : BinaryArray{ | ||
const ba = new BinaryArray(xs.length); | ||
xs.map((v, i) => [v, i]) | ||
.filter((v) => v[0]) | ||
.forEach((v) => { | ||
ba.bitOn(v[1]); | ||
}) | ||
return ba; | ||
} | ||
static deserialize(list : Array<string>, spec : Object, max : number) : BinaryArray{ | ||
const ba = new BinaryArray(max); | ||
list.forEach((v) => { ba.bitOn(spec[v]) }) | ||
return ba; | ||
} | ||
} |
Oops, something went wrong.