Start of binary search for ls command
This commit is contained in:
@@ -105,6 +105,10 @@ export class Bash {
|
||||
return this._terminal.getTerminalWidth();
|
||||
}
|
||||
|
||||
getTerminalFontSize(): number {
|
||||
return this._terminal.getFontSize();
|
||||
}
|
||||
|
||||
hasSudoPerms(uid: number): boolean {
|
||||
return this._group[1].members.includes(uid);
|
||||
}
|
||||
|
||||
@@ -227,9 +227,24 @@ function result_ls(this: Bash, data: any, args: CommandArgs): HTMLElement {
|
||||
return w;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return dummysonoerror; //TEMP SO NO ERROR CUZ RETURNS HTMLElement EVERY TIME, DELETE LATER
|
||||
}
|
||||
|
||||
function checkMaxColumns(this: Bash, files: TreeNode[]) {
|
||||
const paddingWidth: number = 2;
|
||||
const maxWidth: number = (this.getTerminalWidth() / this.getTerminalFontSize()) * 0.8;
|
||||
|
||||
|
||||
//Upper bound set to max width / min column width - 1 character + padding
|
||||
let lowBound: number = 1;
|
||||
let highBound: number = Math.floor(maxWidth / (1 + paddingWidth));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function isValidNodeSortMethod(value: string): value is SortNodeBy {
|
||||
return Object.values(SortNodeBy).includes(value as SortNodeBy);
|
||||
}
|
||||
|
||||
48
src/lib/stores/bash/search.ts
Normal file
48
src/lib/stores/bash/search.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import type { Bash } from "./bash";
|
||||
import type { TreeNode } from "./fs";
|
||||
|
||||
export class Search {
|
||||
|
||||
public static nodeBinarySearch(
|
||||
this: Bash,
|
||||
nodes: TreeNode[],
|
||||
max: number
|
||||
): number {
|
||||
let low: number = 1;
|
||||
let high: number = nodes.length;
|
||||
let c: number = (low + high) / 2;
|
||||
const nameLengths: number[] = nodes.map(node => node.name.length);
|
||||
|
||||
}
|
||||
|
||||
private static binarySearchDNC(
|
||||
n: number,
|
||||
nameLengths: number[],
|
||||
low: number,
|
||||
high: number,
|
||||
max: number): number {
|
||||
|
||||
let c: number = (low + high) / 2;
|
||||
|
||||
if(low + 1 < high) {
|
||||
for(let i = 0; i < c; i++) {
|
||||
const colSize: number =
|
||||
i < (n % c) ? n : n -1;
|
||||
}
|
||||
|
||||
const calculatedWidth: number =
|
||||
nameLengths.reduce((result, value) => result + value) + (c-1) * 2
|
||||
|
||||
if (calculatedWidth <= max) {
|
||||
low = c;
|
||||
return c;
|
||||
}
|
||||
else {
|
||||
high = c;
|
||||
}
|
||||
|
||||
this.binarySearchDNC(n, nameLengths, low, high, max);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ export type PrintData = {
|
||||
export type PageCallbacks = {
|
||||
print: (data: PrintData) => void;
|
||||
getWidth: () => number;
|
||||
getFontSize: () => number;
|
||||
};
|
||||
|
||||
export class Terminal {
|
||||
@@ -110,6 +111,14 @@ export class Terminal {
|
||||
return width;
|
||||
}
|
||||
|
||||
getFontSize(): number {
|
||||
const size = this.callbacks.getFontSize?.();
|
||||
if(!size) { throw new Error('somehow font size is undefined still after all the checks'); }
|
||||
|
||||
console.log(size);
|
||||
return size;
|
||||
}
|
||||
|
||||
getCwd(): string {
|
||||
const fs: VirtualFS = this.bash.getFs();
|
||||
console.log(fs.getPathByInode(this.bash.getCwd()));
|
||||
|
||||
Reference in New Issue
Block a user