Skip to content

Instantly share code, notes, and snippets.

View njofce's full-sized avatar

Nasi njofce

  • Skopje
View GitHub Profile
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;
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);
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;
public class Buffer<T> {
List<T> items;
private int capacity;
public Buffer(int capacity){
this.items = new ArrayList<>(capacity);
this.capacity = capacity;
}
<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>
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));
}
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">
@njofce
njofce / child
Last active March 22, 2020 21:11
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>
<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>
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;