* Create an Index from multiple MultiSet messages. * @param messages - Array of MultiSet messages to build the index from. * @returns A new Index containing all the data from the messages.
(messages: Array<MultiSet<[K, V]>>)
| 162 | * @returns A new Index containing all the data from the messages. |
| 163 | */ |
| 164 | static fromMultiSets<K, V>(messages: Array<MultiSet<[K, V]>>): Index<K, V> { |
| 165 | const index = new Index<K, V>() |
| 166 | |
| 167 | for (const message of messages) { |
| 168 | for (const [item, multiplicity] of message.getInner()) { |
| 169 | const [key, value] = item |
| 170 | index.addValue(key, [value, multiplicity]) |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | return index |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * This method returns a string representation of the index. |