Value arrays work best when random access is the most common form of
access and when incrementally adding elements is not common.
Sequences appear more often than value arrays in most models, especially when
small numbers of elements are involved. Value arrays are useful for larger data sets
that require a lot of random access. Most models will not require them.
Appendix A.2.5 lists value array operations provided by the NModel library.
Value arrays are created from a .NET array:
string[] ratingsArr = new string[]{"Poor", "Average", "Excellent"};
ValueArray
ratings = new ValueArray(ratingsArr);
Assert.AreEqual(ratings[2], "Excellent");
Random access is supported through the C# indexer.
Systems with Complex State 167
10.3.5 Bags or multisets
A bag, or multiset, is an unordered collection of possibly repeating elements. Unlike
sets, an element may appear in a bag more than once. Bags are immutable values,
but you can construct new bags by operations such as union and intersection.
Appendix A.2.6 provides a list of bag operations provided by the NModel library.
Like sets, bags are unordered. Two bags are equal if they contain the number of
occurrences of the same elements. The number of occurrences of a given element is
called its multiplicity.
Bags are useful as a way to abstract the order of a sequence while still allowing
for duplicate values.
Pages:
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236