experimenting with entry
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
import { type FsList, type FsEntry } from "./core"
|
||||
import { type Entry, type Files } from "./entry"
|
||||
|
||||
interface SearchResult<T> {
|
||||
item: T,
|
||||
binary_index: number
|
||||
}
|
||||
interface Search {
|
||||
binary_fs: (cloned_list: FsList, file_name: string) => SearchResult<FsEntry> | undefined,
|
||||
binary_nsort: <T>(list: T[], find: T, start: number, end: number) => SearchResult<T> | undefined,
|
||||
binary_fs_name: <T extends Entry<T>>(cloned_list: Files<T>, file_name: string) => SearchResult<Entry<T>> | undefined,
|
||||
binary_nsort: <T>(list: T[], find: T, start?: number, end?: number) => SearchResult<T> | undefined,
|
||||
binary: <T>(list: T[], find: T) => SearchResult<T> | undefined,
|
||||
linear: <T>(list: T[], find: T) => SearchResult<T> | undefined,
|
||||
}
|
||||
@ -15,9 +15,9 @@ function wrap_result<T>(item: T, binary_index: number): SearchResult<T> {
|
||||
return { item: item, binary_index: binary_index }
|
||||
}
|
||||
|
||||
const search = {} as Search
|
||||
const rfwfs_search = {} as Search
|
||||
|
||||
search.binary = function(list, find) {
|
||||
rfwfs_search.binary = function(list, find) {
|
||||
list.sort()
|
||||
let start = 0
|
||||
let end = list.length-1
|
||||
@ -34,7 +34,7 @@ search.binary = function(list, find) {
|
||||
return
|
||||
}
|
||||
|
||||
search.binary_nsort = function(list, find, start = 0, end = list.length-1) {
|
||||
rfwfs_search.binary_nsort = function(list, find, start = 0, end = list.length-1) {
|
||||
if (start>end) { return }
|
||||
const median = (start+end)>>1
|
||||
if (list[median] === find) {
|
||||
@ -47,16 +47,15 @@ search.binary_nsort = function(list, find, start = 0, end = list.length-1) {
|
||||
}
|
||||
}
|
||||
|
||||
search.binary_fs = function(cloned_list, file_name) {
|
||||
cloned_list.sort((a,z) => a.name.localeCompare(z.name))
|
||||
rfwfs_search.binary_fs_name = function(cloned_entry_list, file_name) {
|
||||
let start = 0
|
||||
let end = cloned_list.length-1
|
||||
let end = cloned_entry_list.length-1
|
||||
while (start<=end) {
|
||||
const median = (start+end)>>1
|
||||
const median_name = cloned_list[median].name
|
||||
const median_name = cloned_entry_list[median].name
|
||||
|
||||
if (median_name === file_name) {
|
||||
return wrap_result(cloned_list[median], median)
|
||||
return wrap_result(cloned_entry_list[median], median)
|
||||
} else if (median_name<file_name) {
|
||||
start = median+1
|
||||
} else {
|
||||
@ -66,7 +65,7 @@ search.binary_fs = function(cloned_list, file_name) {
|
||||
return
|
||||
}
|
||||
|
||||
search.linear = function(list, find) {
|
||||
rfwfs_search.linear = function(list, find) {
|
||||
for (let ind = 0; ind<list.length; ind++) {
|
||||
if (list[ind] === find) {
|
||||
return wrap_result(list[ind], ind)
|
||||
@ -75,4 +74,4 @@ search.linear = function(list, find) {
|
||||
return
|
||||
}
|
||||
|
||||
export default search
|
||||
export default rfwfs_search
|
Reference in New Issue
Block a user