Open Khalian opened 3 years ago
Some initial thoughts
We need a tree data structure here, since we have to deal with hierarchies, consider this ADT
sealed Trait DirectoryTree
object DirectoryNode {
case class SongFile(song: Song) extends DirectoryTree
case class DirectoryNode(folderPath: String, filesUnder: List[Directory]) extends DirectoryTree
}
This will work for the basic cases. Imagine we have this folder hierarchy
Songs (Directory)
- Led Zep (Directory)
- Stairway to heaven, Rain Song, Over the hills and far away
- Greta Van Fleet
- Highway tune, Edge of Darkness, When the curtain falls
Well the root node would be the songs as a diretory node, and then files under would be led zep, and greta van fleet directory node. for led zep, it would have 3 song files, and the same for greta van fleet.
There are multiple things to be very careful about
Needs some design work too.
It basically needs to satisfy these invariants
A song on disk must have at most one copy in memory (this is due to an invariant that Modulo12 is a Read Only query language.
A songs under a directory must be in the cache post a query's execution. On the first time it runs, the cache is created.
The songs under sub directory must be addressible on their own
To illustrate points two and three, consider this hierarchy
Cache(Songs) -> All the above songs Cache(Led Zep) -> { Stairway to heaven, Rain Song, Over the hills and far away } Cache(Greta Van Fleet) -> { Highway tune, Edge of Darkness, When the curtain falls }