add binary search
This commit is contained in:
parent
2fd3530911
commit
9fc0562b61
@ -35,10 +35,11 @@ export default function FolderTree(props) {
|
||||
defaultExpanded={expandedNodes}
|
||||
defaultExpandIcon={<ChevronRightIcon />}
|
||||
onNodeSelect={(event, nodIds) => {
|
||||
// TODO: already sorted, impliment binary search
|
||||
const currentNode = props.flattenNodes.find((aNode) => {
|
||||
return aNode.id === nodIds;
|
||||
});
|
||||
const currentNode = binaryFind(props.flattenNodes, nodIds);
|
||||
// const currentNode = props.flattenNodes.find((aNode) => {
|
||||
// console.log(aNode.id);
|
||||
// return aNode.id === nodIds;
|
||||
// });
|
||||
console.log({ currentNode });
|
||||
if (currentNode != null && currentNode.routePath != null) {
|
||||
router.push(currentNode.routePath);
|
||||
@ -52,6 +53,31 @@ export default function FolderTree(props) {
|
||||
);
|
||||
}
|
||||
|
||||
function binaryFind(sourceList, valToFind) {
|
||||
let leftIndex = 0;
|
||||
let rightIndex = sourceList.length - 1;
|
||||
let middleIndex;
|
||||
while (rightIndex >= leftIndex) {
|
||||
middleIndex = leftIndex + Math.floor((rightIndex - leftIndex) / 2);
|
||||
const currentValue = sourceList[middleIndex];
|
||||
console.log(currentValue);
|
||||
// If the element is present at the middle
|
||||
// itself
|
||||
if (currentValue.id == valToFind) return currentValue;
|
||||
|
||||
// If element is smaller than mid, then
|
||||
// it can only be present in left subarray
|
||||
if (currentValue.id > valToFind) rightIndex = middleIndex - 1;
|
||||
// Else the element can only be present
|
||||
// in right subarray
|
||||
else leftIndex = middleIndex + 1;
|
||||
}
|
||||
|
||||
// We reach here when element is not
|
||||
// present in array
|
||||
return null;
|
||||
}
|
||||
|
||||
function ChevronRightIcon() {
|
||||
return (
|
||||
<svg
|
||||
|
@ -4,7 +4,6 @@ import ListItem, { type ListItemProps } from '../components/portfolio/ListItem'
|
||||
import { UsefulLinksList } from '../components/UsefulLinks/index'
|
||||
import { SocialLinksList } from '../components/SocialLinks/SocialLinks'
|
||||
import type { GetStaticProps } from 'next'
|
||||
import AlienHeader from 'components/portfolio/AlienHeader'
|
||||
import Head from 'next/head'
|
||||
|
||||
interface LandingProps {
|
||||
@ -19,6 +18,7 @@ export default function Landing({ jobs, skills, projects }: LandingProps): React
|
||||
<Head>
|
||||
<title>Triston Armstrong</title>
|
||||
</Head>
|
||||
|
||||
<div>
|
||||
<article className='flex-row align-baseline'>
|
||||
<p>❗👷 This site is under construction 🚧 🏗️ 🚧</p>
|
||||
@ -26,6 +26,16 @@ export default function Landing({ jobs, skills, projects }: LandingProps): React
|
||||
|
||||
<br />
|
||||
|
||||
<div className='flex-row gap-1'>
|
||||
<a href="/notes" target="_blank" className='text-md font-muted font-bold'>🏃 Notes</a>
|
||||
{'|'}
|
||||
<a href="/playground" target="_blank" className='text-md font-muted font-bold'>🏃 Playground</a>
|
||||
{'|'}
|
||||
<a href="/thai" target="_blank" className='text-md font-muted font-bold'>🏃 Thai Playground</a>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
|
||||
<header>
|
||||
<div className="flex-col gap-05">
|
||||
|
||||
@ -47,7 +57,7 @@ export default function Landing({ jobs, skills, projects }: LandingProps): React
|
||||
<hr />
|
||||
</header>
|
||||
|
||||
<main className="">
|
||||
<main >
|
||||
<section>
|
||||
<h4>🤹 Skills <i className='font-muted'><small>(Click me to fast track to docs)</small></i></h4>
|
||||
<div className="flex gap-1" id="skills">
|
||||
@ -71,12 +81,6 @@ export default function Landing({ jobs, skills, projects }: LandingProps): React
|
||||
</main>
|
||||
|
||||
<footer className='flex-col flex-between gap-1 mt-4 '>
|
||||
<div className='flex-row gap-1'>
|
||||
<a href="/notes" target="_blank" className='text-md font-muted font-bold'>🏃 Notes</a>
|
||||
{'|'}
|
||||
<a href="/playground" target="_blank" className='text-md font-muted font-bold'>🏃 Playground</a>
|
||||
</div>
|
||||
|
||||
<div className='flex-row gap-1'>
|
||||
<UsefulLinksList />
|
||||
</div>
|
||||
|
@ -9,7 +9,7 @@ export interface HomeProps {
|
||||
flattenNodes: unknown[]
|
||||
backLinks: LinkType[]
|
||||
}
|
||||
// This trick is to dynamically load component that interact with window object (browser only)
|
||||
|
||||
export default function Home({ content, tree, flattenNodes, backLinks }: HomeProps) {
|
||||
return (
|
||||
<Layout>
|
||||
|
Loading…
Reference in New Issue
Block a user