-
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.
restructuration + rewrite TreeBuilder
- Loading branch information
Showing
6 changed files
with
91 additions
and
101 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
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
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,64 @@ | ||
import {NodeModel} from "../Models/NodeModel"; | ||
import {TeamModel} from "../Models/TeamModel"; | ||
|
||
export class TreeManager { | ||
|
||
private static _nodes: NodeModel[] = []; | ||
|
||
static buildTree(teamList: TeamModel[]): NodeModel { | ||
|
||
let countOf = { | ||
teams: teamList.length, | ||
nodes: (teamList.length * 2) - 1, | ||
}; | ||
|
||
let nodes: NodeModel[] = []; | ||
|
||
for (let i:number = 0; i < countOf.nodes; i++) { | ||
let node = new NodeModel(); | ||
nodes.push(node); | ||
|
||
if (nodes.length > 1) { | ||
let positionOfParent: number = Math.floor(nodes.length/2) - 1; | ||
let parent: NodeModel = nodes[positionOfParent]; | ||
parent.addChild(node); | ||
} | ||
|
||
if (countOf.nodes - i <= countOf.teams) { | ||
node.setTeam(teamList[i+1 - countOf.teams]); | ||
} | ||
} | ||
|
||
this._nodes = this._nodes.concat(nodes); | ||
|
||
return nodes[0]; | ||
} | ||
|
||
static findParentOf(nodeTofind: NodeModel): NodeModel|boolean { | ||
|
||
// For each node | ||
for (let i:number = 0; i < this._nodes.length; i++) { | ||
let node = this._nodes[i]; | ||
|
||
// For each children of the node | ||
for (let j = 0; j < node.children.length; j++) { | ||
let child:NodeModel = node.children[j]; | ||
|
||
// If the child match, return the parent | ||
if (child.id === nodeTofind.id) { | ||
return node; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
static forEachNode(callback: Function): void { | ||
for (let i:number = 0; i < this._nodes.length; i++) { | ||
let node: NodeModel = TreeManager._nodes[i]; | ||
|
||
callback(node); | ||
} | ||
} | ||
} |
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