Arrays

<< Click to Display Table of Contents >>

Navigation:  Using SMILE >

Arrays

The predecessors of SMILE were developed in academia (Decision Systems Laboratory, University of Pittsburgh) before the STL became a part of the C++ standard. The library always had its own classes representing arrays of integers, doubles and strings. To keep the backward compatibility, we retained array classes in SMILE 2, making their public interfaces more consistent.

Numeric arrays are derived from the common DSL_numArray template, which implements a contiguous buffer for a specified numeric type. An array can be resized, and the storage for it can be reserved in advance to avoid large number of heap reallocations, just like std::vector. DSL_numArray also implements small object optimization by including an inline buffer for s specified (small) number of elements. Two widely used specializations of DSL_numArray are DSL_intArray and DSL_doubleArray. All three are documented in the reference section (start from DSL_numArray.) The method names are self-explanatory: Contains returns true when array contains a specified value, SetSize resizes the array, Insert inserts the element at the specific index, etc. Access to array elements is performed through operator[].

SMILE 2.x adds interoperability with std::vector: DSL_numArray::CopyFrom and CopyTo provided to avoid manual loops copying between DSL_numArray and std::vector. The DSL_numArray::begin and end make the SMILE arrays compatible with the algorithms in C++ Standard Library, and with range-based foor loops if C++11 (or later) is enabled. std::initializer_list can be used as an input parameter to DSL_numArray constructor or operator=.

SMILE 2.x fixes the subtle API semantics issue related to the previous implementation of GetSize and NumItems. If the SMILE_NO_V1_COMPATIBILITY is not #defined, then NumItems is still available, but simply calls GetSize. Otherwise NumItems is no longer available.

In addition to numeric arrays, SMILE also defines the DSL_stringArray and DSL_idArray. These classes represent sequences of strings; their API is very similar to the DSL_numArray. Both are described in detail in the reference section.