@@ -3,20 +3,71 @@ package it.unibo.scafi.language.xc
33/**
44 * This trait defines the operations that can be performed on NValues.
55 * @tparam SharedData
6- * the type of the NeighboringValue
6+ * the type of the SharedData.
77 * @tparam DeviceId
88 * the type of the device id
99 */
1010trait NeighborValuesOps [SharedData [_], DeviceId ]:
1111 extension [A ](sharedData : SharedData [A ])
12+ /**
13+ * Returns the default value for unaligned devices.
14+ * @return
15+ * the default value.
16+ */
1217 def default : A
1318
19+ /**
20+ * Maps the values of the SharedData using the provided function.
21+ * @param f
22+ * the mapping function.
23+ * @tparam B
24+ * the type of the mapped values.
25+ * @return
26+ * a new SharedData with the mapped values.
27+ */
1428 def mapValues [B ](f : A => B ): SharedData [B ]
1529
30+ /**
31+ * Maps the values of this SharedData and another SharedData using the provided function. Assumes both SharedData
32+ * are aligned, i.e., they contain values for the same set of device ids.
33+ * @param other
34+ * the other SharedData to map with.
35+ * @param f
36+ * the mapping function that takes a value from this SharedData and a value from the other SharedData.
37+ * @tparam B
38+ * the type of the values in the other SharedData.
39+ * @tparam C
40+ * the type of the mapped values.
41+ * @return
42+ * a new SharedData with the mapped values.
43+ */
1644 def alignedMap [B , C ](other : SharedData [B ])(f : (A , B ) => C ): SharedData [C ]
1745
46+ /**
47+ * Retrieves the value associated with the given device id. If the device is unaligned, returns the default value.
48+ * @param id
49+ * the device id.
50+ * @return
51+ * the value associated with the device id.
52+ * @throws NoSuchElementException
53+ * if the device id is unaligned.
54+ */
1855 def apply (id : DeviceId ): A
1956
57+ /**
58+ * Retrieves the value associated with the given device id, if the device is aligned.
59+ * @param id
60+ * the device id.
61+ * @return
62+ * an option containing the value if the device is aligned, or None if it is unaligned.
63+ */
64+ def get (id : DeviceId ): Option [A ]
65+
66+ /**
67+ * Retrieves a map of all device ids to their associated values.
68+ * @return
69+ * a map of device ids to values.
70+ */
2071 def values : Map [DeviceId , A ]
2172
2273 private [xc] def set (id : DeviceId , value : A ): SharedData [A ]
0 commit comments