Librerías \ HashMap

Referencia para la versión de Wiring 1.0 Build 0100+. Si tiene una versión previa, use la referencia incluida con su software. Si encuentra errores o tiene comentarios, no dude en contactarnos.

Nombre

HashMap

Ejemplos
#include <HashMap.h>
//create hashMap that pairs char* to int and can hold 3 pairs
CreateHashMap(hashMap, char*, int, 3); 

void setup()
{
  Serial.begin(9600);
  //add and store keys and values
  hashMap["newKey"] = 12;
  hashMap["otherKey"] = 13;

  //check if overflow (there should not be any danger yet)
  Serial.print("Will the hashMap overflow now [after 2 assigns] ?: ");
  Serial.println(hashMap.willOverflow());

  hashMap["lastKey"] = 14;

  //check if overflow (this should be true, as we have added 3 of 3 pairs)
  Serial.print("Will the hashMap overflow now [after 3 assigns] ?: ");
  Serial.println(hashMap.willOverflow());

  //it will overflow, but this won't affect the code.
  hashMap["test"] = 15;

  //change the value of newKey
  Serial.print("The old value of newKey: ");
  Serial.println(hashMap["newKey"]);

  hashMap["newKey"]++;

  Serial.print("The new value of newKey (after hashMap['newKey']++): ");
  Serial.println(hashMap["newKey"]);

  //remove a key from the hashMap
  hashMap.remove("otherKey");

  //this should work as there is now an availabel spot in the hashMap
  hashMap["test"] = 15;

  printHashMap();
}

void loop() {
}

void printHashMap() 
{
  for (int i=0; i<hashMap.size(); i++) 
  {
    Serial.print("Key: ");
    Serial.print(hashMap.keyAt(i));
    Serial.print(" Value: ");
    Serial.println(hashMap.valueAt(i));
  }
}
Descripción Implementación de estructura de datos HashMap para la plataforma Wiring.
Sintaxis
HashMap(compare)
Métodos
CreateHashMap()
size()
keyAt()
valueAt()
willOverflow()
indexOf()
contains()
remove()
setNullValue()
Parámetros
compare Función opcional para comparar una llave contra otra (para tipos complejos)
Retorna Ninguno
Uso Application
Updated on July 07, 2011 11:15:02pm PDT

Creative Commons License