#ifndef __macrovsa_AssociativeNetwork__ #define __macrovsa_AssociativeNetwork__ #include "Symbol.hpp" #include "AssociativeMap.hpp" namespace macrovsa { /** * @class AssociativeNetwork * @description Implements a macroscopic ersatz of a VSA associative network. * - An associative network is created adding new key/value pairs of symbol. * - It is implemented via a matrix of the form `>_i value_i key_i^T` * @param {string} [name] An optional name. By default, a `#index` unique name is generated. * @extends AssociativeMap */ class AssociativeNetwork: public Symbol { // Non assignable AssociativeMap& operator = (const AssociativeMap&) = delete; AssociativeNetwork(const AssociativeNetwork&) = delete; // Double indexing mechanism AssociativeMap keys, values; public: AssociativeNetwork() {} AssociativeNetwork(String name) : Symbol(name) {} /** * @function add * @memberof AssociativeNetwork * @instance * @description Adds a new symbol pair to the container. * @param {Symbol} key The symbol key to add. * @param {Symbol} value The symbol value to add. */ void add(const Symbol& key, const Symbol& value) { values.add(key, value); keys.add(value, key); } /** * @function getValue * @memberof AssociativeMap * @instance * @description Returns an approximate value of the associative map by unbinding. * @param {Symbol|String} key The symbol key `key_i`. * @return {Symbol} value A reference to the stored values as a bundling, available until program end. */ const Symbol& getValue(const Symbol& key) const { return values.get(key); } const Symbol& getValue(String key) const { Symbol *skey = new Symbol(key); const Symbol& result = values.get(*skey); delete skey; return result; } /** * @function getKey * @memberof AssociativeMap * @instance * @description Returns an approximate key of the associative map by unbinding. * @param {Symbol|String} value The symbol value `value_i`. * @return {Symbol} key A reference to the stored keys as a bundling, available until program end. */ const Symbol& getKey(const Symbol& value) const { return keys.get(value); } const Symbol& getKey(String value) const { Symbol *svalue = new Symbol(value); const Symbol& result = values.get(*svalue); delete svalue; return result; } }; } #endif