summaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
authorEdoardo La Greca2025-08-07 16:29:16 +0200
committerEdoardo La Greca2025-08-07 16:33:27 +0200
commit158c0e0ef40c16d9ae38a7fa70b10b893a80d7b3 (patch)
tree46c860c712d6f399b731a86fa4cde912d255d8e6 /src/main/kotlin
parent0857a08a2f44c7c20e340f8d3e20eccdbe867006 (diff)
turn FIDInfo into PathInfo
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/FIDInfo.kt42
-rw-r--r--src/main/kotlin/PathInfo.kt62
2 files changed, 62 insertions, 42 deletions
diff --git a/src/main/kotlin/FIDInfo.kt b/src/main/kotlin/FIDInfo.kt
deleted file mode 100644
index dbbc945..0000000
--- a/src/main/kotlin/FIDInfo.kt
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * This class holds all info about File IDs (FIDs).
- */
-class FIDInfo() {
- private val inUse: MutableSet<FID> = mutableSetOf()
-
- /**
- * A single FID.
- *
- * @param fid The actual FID value.
- * @param path The path of the FID, represented as successive path name elements.
- * @param qid The QID associated with the FID.
- */
- data class FID(val fid: UInt, val path: List<String>, val qid: QID)
-
- /**
- * Add a FID with the associated file path and QID.
- */
- fun addFID(fid: FID) {
- this.inUse.add(fid)
- }
-
- /**
- * Find the path associated to a FID.
- *
- * @param fid The FID to find the path of.
- * @return The path if [fid] could be found, or null otherwise.
- */
- fun findPathByFID(fid: UInt): List<String>? {
- return this.inUse.find { x -> x.fid == fid }?.path
- }
-
- /**
- * Find the FID associated to a path.
- *
- * @param path The path to find the FID of.
- * @return The FID if [path] has an associated FID, or null otherwise.
- */
- fun findFIDByPath(path: List<String>): UInt? {
- return this.inUse.find { x -> x.path == path }?.fid
- }
-} \ No newline at end of file
diff --git a/src/main/kotlin/PathInfo.kt b/src/main/kotlin/PathInfo.kt
new file mode 100644
index 0000000..c9ff29e
--- /dev/null
+++ b/src/main/kotlin/PathInfo.kt
@@ -0,0 +1,62 @@
+/**
+ * This class holds all info about paths, their FIDs, and their QIDs.
+ */
+class PathInfo() {
+ private val paths: MutableSet<Path> = mutableSetOf()
+
+ /**
+ * Information about a path. Each FID maps to one path but not all paths have FIDs (injective). On the other hand,
+ * one QID can be shared with different paths and FIDs.
+ *
+ * FIDs are optional because some R-messages only return QIDs for certain files (e.g. walk).
+ *
+ * @param path The path.
+ * @param fid The optional FID associated with the path.
+ * @param qid The QID associated with the path.
+ */
+ data class Path(val path: List<String>, val fid: UInt?, val qid: QID)
+
+ /**
+ * Add a path.
+ */
+ fun addPath(path: Path) {
+ this.paths.add(path)
+ }
+
+ /**
+ * Find the FID associated with a path.
+ *
+ * @param path The path to find the FID of.
+ * @return The FID if [path] has an associated FID, or null otherwise.
+ */
+ fun findFIDByPath(path: List<String>): UInt? {
+ return this.paths.find { x -> x.path == path }?.fid
+ }
+
+ /**
+ * Find the QID associated to a path.
+ *
+ * @param path The path to find the QID of.
+ * @return The QID if [path] could be found, or null otherwise.
+ */
+ fun findQIDByPath(path: List<String>): QID? {
+ return this.paths.find { x -> x.path == path }?.qid
+ }
+
+ /**
+ * Find the path associated to a FID.
+ *
+ * @param fid The FID to find the path of.
+ * @return The path if [fid] could be found, or null otherwise.
+ */
+ fun findPathByFID(fid: UInt): List<String>? {
+ return this.paths.find { x -> x.fid == fid }?.path
+ }
+
+ /**
+ * Retrieve all paths
+ */
+ fun getAllPaths(): Set<Path> {
+ return this.paths.toSet()
+ }
+} \ No newline at end of file