This repository was archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 115
Refactor Content.rec(..) function to support tail-optimisation #417
Open
dmytroDragan
wants to merge
9
commits into
microsoft:master
Choose a base branch
from
dmytroDragan:issue-400
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
336728d
Merge pull request #1 from microsoft/master
dmytroDragan 50bc56a
remove arrangement
ddrag-softserve d9e93a1
scalafmt only recFilesApply func
ddrag-softserve 848b493
Update src/main/scala/com/microsoft/hyperspace/index/IndexLogEntry.scala
dmytroDragan 90046da
Update src/main/scala/com/microsoft/hyperspace/index/IndexLogEntry.scala
dmytroDragan eb4d5d1
rename function and added description
ddrag-softserve 99e50d7
Merge pull request #2 from microsoft/master
dmytroDragan a0c4d21
fixed tests
ddrag-softserve e3c6075
Merge branch 'master' into issue-400
ddrag-softserve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ import org.apache.spark.sql.types.{DataType, StructType} | |
|
|
||
| import com.microsoft.hyperspace.{BuildInfo, HyperspaceException} | ||
| import com.microsoft.hyperspace.actions.Constants | ||
| import com.microsoft.hyperspace.index.Content.recFilesApply | ||
| import com.microsoft.hyperspace.util.PathUtils | ||
|
|
||
| // IndexLogEntry-specific fingerprint to be temporarily used where fingerprint is not defined. | ||
|
|
@@ -45,27 +46,17 @@ case class Content(root: Directory, fingerprint: NoOpFingerprint = NoOpFingerpri | |
| @JsonIgnore | ||
| lazy val files: Seq[Path] = { | ||
| // Recursively find files from directory tree. | ||
| rec(new Path(root.name), root, (f, prefix) => new Path(prefix, f.name)) | ||
| recFilesApply(new Path(root.name), root, (f, prefix) => new Path(prefix, f.name)) | ||
| } | ||
|
|
||
| @JsonIgnore | ||
| lazy val fileInfos: Set[FileInfo] = { | ||
| rec( | ||
| recFilesApply( | ||
| new Path(root.name), | ||
| root, | ||
| (f, prefix) => | ||
| FileInfo(new Path(prefix, f.name).toString, f.size, f.modifiedTime, f.id)).toSet | ||
| } | ||
|
|
||
| private def rec[T]( | ||
| prefixPath: Path, | ||
| directory: Directory, | ||
| func: (FileInfo, Path) => T): Seq[T] = { | ||
| val files = directory.files.map(f => func(f, prefixPath)) | ||
| files ++ directory.subDirs.flatMap { dir => | ||
| rec(new Path(prefixPath, dir.name), dir, func) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| object Content { | ||
|
|
@@ -111,6 +102,43 @@ object Content { | |
| None | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Apply `func` to each file in directory recursively. | ||
| * | ||
| * @param prefixPath Root prefix | ||
| * @param directory Root directory | ||
| * @param func Function which would apply to current prefix and file | ||
| * @tparam T | ||
| * @return Result list of applying function to all files | ||
| */ | ||
| def recFilesApply[T]( | ||
| prefixPath: Path, | ||
|
||
| directory: Directory, | ||
| func: (FileInfo, Path) => T): Seq[T] = { | ||
| @tailrec | ||
| def recAcc[A]( | ||
| dirMap: List[(Path, Seq[Directory])], | ||
| func: (FileInfo, Path) => A, | ||
| acc: Seq[A] = Seq.empty): Seq[A] = { | ||
| dirMap match { | ||
| case Nil => acc | ||
| case (curPrefixPath, curDirs) :: otherDirs => | ||
| val curAcc = for { | ||
| dir <- curDirs | ||
| file <- dir.files | ||
| } yield func(file, new Path(curPrefixPath, dir.name)) | ||
|
|
||
| val newLevels = curDirs | ||
| .filter(_.subDirs.nonEmpty) | ||
| .map(dir => (new Path(curPrefixPath, dir.name), dir.subDirs)) | ||
|
|
||
| recAcc(otherDirs ++ newLevels, func, curAcc ++ acc) | ||
| } | ||
| } | ||
|
|
||
| recAcc(List(prefixPath -> Seq(directory)), func) | ||
dmytroDragan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.