This file contains hidden or 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
| class Buffer<T> { | |
| List<T> items; | |
| private int capacity; | |
| private Lock pcLock = new ReentrantLock(); | |
| Buffer(int capacity){ | |
| this.items = new ArrayList<>(capacity); | |
| this.capacity = capacity; |
This file contains hidden or 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
| public class Buffer<T> { | |
| List<T> items; | |
| private int capacity; | |
| private Lock canProduce = new ReentrantLock(); | |
| private Lock canConsume= new ReentrantLock(); | |
| public Buffer(int capacity){ | |
| this.items = new ArrayList<>(capacity); |
This file contains hidden or 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
| import java.util.ArrayList; | |
| import java.util.List; | |
| import java.util.concurrent.locks.Lock; | |
| import java.util.concurrent.locks.ReentrantLock; | |
| public class Buffer<T> { | |
| List<T> items; | |
| private int capacity; |
This file contains hidden or 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
| public class Buffer<T> { | |
| List<T> items; | |
| private int capacity; | |
| public Buffer(int capacity){ | |
| this.items = new ArrayList<>(capacity); | |
| this.capacity = capacity; | |
| } |
This file contains hidden or 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
| <div *ngIf="treeNode"> | |
| <cdk-virtual-scroll-viewport | |
| [style.height.px]="500" | |
| style="width: 900px; margin-top: 10px;" | |
| minBufferPx="200" | |
| maxBufferPx="350" | |
| itemSize="20"> | |
| <div *cdkVirtualFor="let ch of flatTree; templateCacheSize: 20"> | |
| <app-tree-child [node]="ch"></app-tree-child> |
This file contains hidden or 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
| getFlatTree(): TreeNode[] { | |
| return this.flatTreeRecursive(this._root); | |
| } | |
| private flatTreeRecursive(root: TreeNode): TreeNode[] { | |
| let res = []; | |
| for (let c of root.children) { | |
| res.push(c); | |
| res = res.concat(this.flatTreeRecursive(c)); | |
| } |
This file contains hidden or 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
| import { Component, OnInit, Input, SimpleChanges } from '@angular/core'; | |
| import { Tree } from '../models/tree'; | |
| import {TreeNode} from '../models/tree-models'; | |
| @Component({ | |
| selector: 'app-tree-parent', | |
| template:` | |
| <h2>Tree data visualized </h2> | |
| <div *ngIf="treeNode"> |
This file contains hidden or 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
| import { Component, OnInit, Input } from '@angular/core'; | |
| import { TreeNode } from '../models/tree-models'; | |
| @Component({ | |
| selector: 'app-tree-child', | |
| template: ` | |
| <div class="child-contents-container"> | |
| <div> | |
| <p>{{node.data}}</p> | |
| <div> |
This file contains hidden or 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
| <div class="child-contents-container"> | |
| <div> | |
| <p>{{node.data}}</p> | |
| <div> | |
| <div class="children-container"> | |
| <app-tree-child *ngFor="let ch of node.children" [node]="ch"></app-tree-child> | |
| </div> | |
| </div> |
This file contains hidden or 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
| export class TreeNode<T> { | |
| private _data: T; | |
| private _parent: TreeNode<T>; | |
| private _children: TreeNode<T>[]; | |
| constructor(data: T, parent: TreeNode<T>, children: TreeNode<T>[] = []) { | |
| this._data = data; | |
| this._parent = parent; | |
| this._children = children; |