[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re:
From: |
Tavian Barnes |
Subject: |
Re: |
Date: |
Mon, 18 Mar 2019 14:16:39 -0400 |
> On 3/14/19 9:49 PM, Budi wrote:
> > How do we make findutil search in ply by ply depth instead of binary
> > search tree, ie. how to make it search on a ply depth thoroughly
> > without getting inside any directory there before all par member is
> > read and retrieved
> I'm not exactly sure what your question is, but POSIX already requires
> 'find' to default to breadth-first traversal (find visits all files in
> the current directory before descending to a subdirectory) so that the
> -prune predicate works; but if the -depth predicate is supplied, then
> 'find' executes in depth-first traversal (subdirectories are visited
> before files in the parent directory).
This is not true, or at least not the definition of "breadth-first"
I'm familiar with. To me, depth-first means "push children on a
stack" (LIFO), breadth-first means "push children on a queue" (FIFO),
and post-order means "visit children before parents."
find does a depth-first traversal:
$ mkdir -p a/b c/d
$ find .
.
./a
./a/b
./c
./c/d
(Depth-first because a/b is visited before ./c) "-depth" does a
post-order traversal that is still depth first, i.e.
$ find . -depth
./a/b
./a
./c/d
./c
.
Breadth-first would look like
$ bfs .
.
./a
./c
./a/b
./c/d
and can be accomplished with Dale R. Worley's -{min,max}depth loop
(which makes it an iterative deepening search actually), or with tools
other than find (like bfs above that I wrote).
--
Tavian Barnes
[Prev in Thread] |
Current Thread |
[Next in Thread] |