Compare commits

...

3 Commits

Author SHA1 Message Date
e09891482e not necessary 2025-02-26 14:24:25 -05:00
f7e678190d move rfwfs into rt 2025-02-26 14:18:05 -05:00
22df34ed43 binary searching for files WIP 2025-02-26 02:03:07 -05:00
10 changed files with 99 additions and 91 deletions

View File

@ -1,5 +1,5 @@
<!doctype html>
<html lang="en">
<html>
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width"/>

View File

@ -1,5 +1,5 @@
import { cyan, green } from "../shell/color"
import { get_working_dir_name } from "../shell/rfwfs/library"
import { get_working_dir_name } from "../rfwfs/library"
import create from "./create"

View File

@ -8,8 +8,9 @@ const enum Permissions {
rw
}
type FsList = FsEntry[]
type FsEntry = Entry<{}>
type FsDirectory = Entry<FsEntry[]>
type FsDirectory = Entry<FsList>
type File = string
interface Entry<T = File> {
@ -30,6 +31,7 @@ function Entry<T = File>(name: string, inner: T, permissions: Permissions): Entr
export {
type FsDirectory,
type FsEntry,
type FsList,
EntryType,
Permissions,
Entry

View File

@ -48,14 +48,16 @@ search.binary_nsort = function(list, find, start = 0, end = list.length-1) {
}
search.binary_fs = function(cloned_list, file_name) {
cloned_list.sort()
cloned_list.sort((a,z) => a.name.localeCompare(z.name))
let start = 0
let end = cloned_list.length-1
while (start<=end) {
const median = (start+end)>>1
if (cloned_list[median].name === file_name) {
const median_name = cloned_list[median].name
if (median_name === file_name) {
return wrap_result(cloned_list[median], median)
} else if (cloned_list[median].name !== file_name) {
} else if (median_name<file_name) {
start = median+1
} else {
end = median-1

85
src/rt/rfwfs/library.ts Normal file
View File

@ -0,0 +1,85 @@
import { type FsDirectory, type FsEntry } from "./core"
import fstree from "./tree"
import index from "./index"
let cached_dir = fstree[0] //start at root
let working_path = ["/", "home", "user"]
const clone_working_path = () => [...working_path]
function get_working_dir_name() {
return working_path[working_path.length-1]
}
function get_working_dir_name_full(): string {
const w_dir_clone = clone_working_path()
const root = w_dir_clone.shift()
if (root) {
return root+w_dir_clone.join("/")
}
return "shift-error"
}
const enum SetDirStatus {
Valid,
NotFound,
NotADirectory,
Invalid
}
interface FsIterEntry {
readonly entry: FsDirectory | null,
readonly status: SetDirStatus
}
function find_fs_dir(working_dir_path_clone: string[], find_dir_name: string): FsIterEntry {
let cached_dir_clone = cached_dir.inner
for (let path_i = 0; path_i<working_dir_path_clone.length; path_i++) {
if (cached_dir_clone) {
let cached_dir_file_names: string[] = []
cached_dir_clone.forEach((file, file_i) => cached_dir_file_names.push(file.name))
const search_result = index.binary(cached_dir_clone, fstree[0])
if (working_dir_path_clone[path_i] === find_dir_name) {
cached_dir_clone = cached_dir_clone
if (path_i === working_dir_path_clone.length) {
const search_result = index.binary(cached_dir_file_names, find_dir_name)
if (search_result) {
}
} else {
continue
}
}
}
return { entry: null, status: SetDirStatus.Invalid }
}
return { entry: null, status: SetDirStatus.NotFound }
}
function set_working_dir(name: string): SetDirStatus {
if (name === ".") { return SetDirStatus.Valid }
const w_dir_clone = clone_working_path()
if (name === "..") {
w_dir_clone.pop()
} else {
w_dir_clone.push(name)
}
}
function get_working_dir_entries(): FsEntry[] {
}
export {
get_working_dir_name,
get_working_dir_name_full,
get_working_dir_entries,
set_working_dir,
SetDirStatus
}

View File

@ -1,4 +1,4 @@
import { set_working_dir, SetDirStatus } from "../../rfwfs/library"
import { set_working_dir, SetDirStatus } from "../../../rfwfs/library"
import type { Args, Term } from "../list"
import stdout from "../../../elements/stdout"

View File

@ -1,7 +1,7 @@
import type { Args, Term } from "../list";
import { blue } from "../../color";
import { get_working_dir_entries } from "../../rfwfs/library";
import { EntryType, FsEntry } from "../../rfwfs/core";
import { get_working_dir_entries } from "../../../rfwfs/library";
import { EntryType, FsEntry } from "../../../rfwfs/core";
import stdout, { stdout_horizontal_elements } from "../../../elements/stdout";
import create from "../../../elements/create";

View File

@ -1,4 +1,4 @@
import { get_working_dir_name_full } from "../../rfwfs/library";
import { get_working_dir_name_full } from "../../../rfwfs/library";
import type { Args, Term } from "../list";
import stdout from "../../../elements/stdout";

View File

@ -1,81 +0,0 @@
import { EntryType, fs, type FsDirectory, type FsEntry } from "./core"
let working_dir = ["/", "home", "user"]
function get_working_dir_name() {
return working_dir[working_dir.length-1]
}
function get_working_dir_name_full(): string {
const w_dir_clone = [...working_dir]
const root = w_dir_clone.shift()
if (root) {
return root+w_dir_clone.join("/")
}
return "shift-error"
}
const enum SetDirStatus {
Valid,
NotFound,
NotADirectory
}
interface FsIterEntry {
readonly entry: FsDirectory | null,
readonly status: SetDirStatus
}
function iter_fs_to_goal(w_dir_clone: string[]): FsIterEntry {
let next_iter = fs[0]
for (const w_dir of w_dir_clone) {
if (w_dir === "/") { continue }
if (next_iter && next_iter.inner) {
const found = next_iter.inner.find(entry => entry.name === w_dir)
if (!found) {
return { entry: null, status: SetDirStatus.NotFound }
}
if (found.type !== EntryType.Directory) {
return { entry: null, status: SetDirStatus.NotADirectory }
}
if (found.name === w_dir_clone[w_dir_clone.length-1]) {
return { entry: next_iter, status: SetDirStatus.Valid }
} else {
next_iter = found.inner as FsDirectory
}
}
}
return { entry: null, status: SetDirStatus.NotFound }
}
function set_working_dir(name: string): SetDirStatus {
if (name === ".") { return SetDirStatus.Valid }
const w_dir_clone = [...working_dir]
if (name === "..") { w_dir_clone.pop() } else { w_dir_clone.push(name) }
const iter_status = iter_fs_to_goal(w_dir_clone)
if (iter_status.status === SetDirStatus.Valid) {
working_dir = w_dir_clone
}
return iter_status.status
}
function get_working_dir_entries(): FsEntry[] {
const entries: FsEntry[] = []
const w_dir_clone = [...working_dir]
const iter_status = iter_fs_to_goal(w_dir_clone)
if (iter_status.entry && iter_status.entry.inner) {
iter_status.entry.inner.forEach(dir => entries.push(dir))
}
return entries
}
export {
get_working_dir_name,
get_working_dir_name_full,
get_working_dir_entries,
set_working_dir,
SetDirStatus
}