1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef __macrovsa_Array__
#define __macrovsa_Array__

#include "AssociativeMap.hpp"
#include "Number.hpp"

namespace macrovsa {
  /**
   * @class Array
   * @description Implements a macroscopic ersatz of a VSA indexed list.
   * - An indexed list is created adding new index/value pairs.
   * - It simply corresponds to an [AssociativeMap](./AssociativeMap.html) with [Number](./Number.html) as key.
   * - It is implemented via [Bundling](./Bundling.html) and [Binding](./Binding.html), without using a C++ `std::vector`.
   * @extends AssociativeMap
   */
  class Array: public AssociativeMap {
public:

    /**
     * @function add
     * @memberof Array
     * @instance
     * @description Adds a new symbol pair to the container.
     * - Adding twice the same index/value pair corresponds to adding their belief level `tau`.
     * @param {uint} [index] The symbol index to add or modify. By default the symbol is appended.
     * @param {Symbol} value The symbol value to add.
     */
    virtual void add(unsigned int index, const Symbol& value)
    {
      AssociativeMap::add(Number::getInt(index), value);
    }
    virtual void add(const Symbol& value)
    {
      Array::add((unsigned int) AssociativeMap::get().size(), value);
    }
    /**
     * @function get
     * @memberof Array
     * @instance
     * @description Returns an approximate value of the associative map by unbinding.
     * @param {uint} index The symbol index.
     * @return {Symbol} value A reference to the stored value, available until program end.
     */
    const Symbol& get(unsigned int index) const
    {
      return AssociativeMap::get(Number::getInt(index));
    }
  };
}

#endif