-
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 #1 from Aleff13/dev
- Loading branch information
Showing
16 changed files
with
9,379 additions
and
297 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,25 @@ | ||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: [master, dev] | ||
pull_request: | ||
branches: [master, dev] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [18.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm ci | ||
- run: npm run build --if-present | ||
- run: npm test |
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,6 @@ | ||
{ | ||
"files.associations": { | ||
"*.tcc": "cpp", | ||
"iostream": "cpp" | ||
} | ||
} |
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,58 @@ | ||
var tree = { | ||
children: { | ||
children: { | ||
children: { | ||
children: { | ||
children: { | ||
"id": "12345678", | ||
"type": "here" | ||
}, | ||
"id": "1234567", | ||
"type": "tp" | ||
}, | ||
"id": "123456", | ||
"type": "tp" | ||
}, | ||
"id": "12345", | ||
"type": "tp" | ||
}, | ||
"id": "1234", | ||
"type": "tp" | ||
}, | ||
"id": "123", | ||
"type": "tp" | ||
}; | ||
var getIdOfFirstType = function (tree, type) { | ||
if (tree.type == type) { | ||
return tree.id; | ||
} | ||
if (!(tree === null || tree === void 0 ? void 0 : tree.children)) { | ||
return null; | ||
} | ||
return getIdOfFirstType(tree === null || tree === void 0 ? void 0 : tree.children, type); | ||
}; | ||
var getAllIdsByType = function (tree, type, ids) { | ||
if (ids === void 0) { ids = []; } | ||
if (tree.type == type) { | ||
ids.push(tree.id); | ||
} | ||
if (!(tree === null || tree === void 0 ? void 0 : tree.children)) { | ||
return ids; | ||
} | ||
return getAllIdsByType(tree === null || tree === void 0 ? void 0 : tree.children, type, ids); | ||
}; | ||
var getNodeById = function (tree, id) { | ||
if (tree.id == id) { | ||
return tree.children; | ||
} | ||
if (!(tree === null || tree === void 0 ? void 0 : tree.children)) { | ||
return null; | ||
} | ||
return getNodeById(tree === null || tree === void 0 ? void 0 : tree.children, id); | ||
}; | ||
var firstIdOfType = getIdOfFirstType(tree, "here"); | ||
console.log(firstIdOfType); | ||
var allIdsOfTypeTp = getAllIdsByType(tree, "tp"); | ||
console.log(allIdsOfTypeTp); | ||
var firstNodeOfId = getNodeById(tree, "12345"); | ||
console.log(firstNodeOfId); |
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,82 @@ | ||
interface Children { | ||
children?: Children | ||
id: string | ||
type: string | ||
} | ||
|
||
interface Tree { | ||
children?: Children | ||
id: string | ||
type: string | ||
} | ||
|
||
const tree = { | ||
children: { | ||
children: { | ||
children: { | ||
children: { | ||
children: { | ||
"id": "12345678", | ||
"type": "here" | ||
}, | ||
"id": "1234567", | ||
"type": "tp" | ||
}, | ||
"id": "123456", | ||
"type": "tp" | ||
}, | ||
"id": "12345", | ||
"type": "tp" | ||
}, | ||
"id": "1234", | ||
"type": "tp" | ||
}, | ||
"id": "123", | ||
"type": "tp" | ||
} | ||
|
||
const getIdOfFirstType = (tree: Tree | Children, type: string): void | string | null => { | ||
if (tree.type == type) { | ||
return tree.id | ||
} | ||
|
||
if (!tree?.children) { | ||
return null | ||
} | ||
|
||
return getIdOfFirstType(tree?.children, type) | ||
} | ||
|
||
const getAllIdsByType = (tree: Tree | Children, type: string, ids: string[] = []): void | string[] | null => { | ||
if (tree.type == type) { | ||
ids.push(tree.id) | ||
} | ||
|
||
if (!tree?.children) { | ||
return ids | ||
} | ||
|
||
return getAllIdsByType(tree?.children, type, ids) | ||
} | ||
|
||
const getNodeById = (tree: Tree | Children, id: string): void | Children | null => { | ||
if (tree.id == id) { | ||
return tree.children | ||
} | ||
|
||
if (!tree?.children) { | ||
return null | ||
} | ||
|
||
return getNodeById(tree?.children, id) | ||
} | ||
|
||
const firstIdOfType = getIdOfFirstType(tree, "here") | ||
console.log(firstIdOfType) | ||
|
||
const allIdsOfTypeTp = getAllIdsByType(tree, "tp") | ||
console.log(allIdsOfTypeTp) | ||
|
||
const firstNodeOfId = getNodeById(tree, "12345") | ||
console.log(firstNodeOfId) | ||
|
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 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var stack_lib_1 = require("./stack.lib"); | ||
var Stack = /** @class */ (function () { | ||
function Stack() { | ||
this.obj = stack_lib_1["default"].createStack(); | ||
} | ||
Stack.prototype.push = function (value) { | ||
stack_lib_1["default"].push(this.obj, value); | ||
}; | ||
Stack.prototype.pop = function () { | ||
return stack_lib_1["default"].keyToHash(this.obj); | ||
}; | ||
Stack.prototype.peek = function () { | ||
return stack_lib_1["default"].peek(this.obj); | ||
}; | ||
Stack.prototype.destructor = function () { | ||
stack_lib_1["default"].deleteStack(this.obj); | ||
}; | ||
return Stack; | ||
}()); | ||
exports["default"] = Stack; | ||
// const stack = new Stack(); | ||
// stack.push("first"); | ||
// stack.peek(); | ||
// console.log(stack.peek()) |
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,33 @@ | ||
import stackLib from './stack.lib'; | ||
|
||
class Stack { | ||
obj: any; | ||
|
||
constructor() { | ||
this.obj = stackLib.createStack(); | ||
} | ||
|
||
push(value: string){ | ||
stackLib.push(this.obj, value); | ||
} | ||
|
||
pop() { | ||
return stackLib.keyToHash(this.obj); | ||
} | ||
|
||
peek() { | ||
return stackLib.peek(this.obj); | ||
} | ||
|
||
destructor() { | ||
stackLib.deleteStack(this.obj); | ||
} | ||
} | ||
|
||
export default Stack | ||
|
||
// const stack = new Stack(); | ||
// stack.push("first"); | ||
// stack.peek(); | ||
|
||
// console.log(stack.peek()) |
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,12 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var ffi = require("ffi-napi"); | ||
//import c++ lib | ||
var stackLib = ffi.Library("../cpp/stack.so", { | ||
"createStack": ['pointer', []], | ||
'deleteStack': ['void', ['pointer']], | ||
"push": ['void', ['pointer', 'string']], | ||
"pop": ['void', ['pointer']], | ||
"peek": ['string', ['pointer']] | ||
}); | ||
exports["default"] = stackLib; |
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,11 @@ | ||
const ffi = require("ffi-napi") | ||
//import c++ lib | ||
const stackLib = ffi.Library("../cpp/stack.so", { | ||
"createStack": ['pointer', []], | ||
'deleteStack': ['void', ['pointer']], | ||
"push": ['void', ['pointer', 'string']], | ||
"pop": ['void', ['pointer']], | ||
"peek": ['string', ['pointer']], | ||
}); | ||
|
||
export default stackLib |
Binary file not shown.
Binary file not shown.
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,5 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
Oops, something went wrong.