-
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.
commit 024fedd Author: you21979 <you2197901@gmail.com> Date: Wed Mar 28 18:17:18 2018 +0900 add tstest commit 6afc41d Author: you21979 <you2197901@gmail.com> Date: Wed Mar 28 17:32:41 2018 +0900 fix index.ts commit 6911c0b Author: you21979 <you2197901@gmail.com> Date: Wed Mar 28 17:25:13 2018 +0900 add .npmignore commit 66c54cc Author: you21979 <you2197901@gmail.com> Date: Wed Mar 28 17:20:21 2018 +0900 compile es5 commit 7c02411 Author: you21979 <you2197901@gmail.com> Date: Wed Mar 28 17:11:20 2018 +0900 refactoring commit fe23222 Author: you21979 <you2197901@gmail.com> Date: Wed Mar 28 17:00:11 2018 +0900 ci commit 1eddede Author: you21979 <you2197901@gmail.com> Date: Wed Mar 28 16:57:08 2018 +0900 ci commit 2f51fc7 Author: you21979 <you2197901@gmail.com> Date: Wed Mar 28 16:50:14 2018 +0900 ci commit f20799e Author: you21979 <you2197901@gmail.com> Date: Wed Mar 28 16:41:13 2018 +0900 typescript first commit
- 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.