braydenanderson2014 / C-Arduino-Libraries

This repository contains C++ and Arduino Libraries that are lightweight and easy to use. All libraries were created/mimicked by me and chatgpt.
Apache License 2.0
13 stars 0 forks source link

/C-Arduino-Libraries/blob/main/lib/Map/src/Map.h Count is incorrect #75

Closed huster-songtao closed 5 months ago

huster-songtao commented 5 months ago

old version

  V& operator[](const K& key) {
    MapNode** pp = &head;
    while (*pp != nullptr && (*pp)->key != key) {
      pp = &(*pp)->next;
    }
    if (*pp != nullptr) {
      return (*pp)->value;
    } else {
      MapNode* newNode = new MapNode{ key, V(), nullptr };
      *pp = newNode;
      return newNode->value;
    }
  }

// Insert a key-value pair into the pin map pinMap["D0"] = D0; pinMap["D1"] = D1; pinMap["D2"] = D2; pinMap["D3"] = D3; pinMap["D4"] = D4; pinMap["D5"] = D5; pinMap["D6"] = D6; pinMap["D7"] = D7; pinMap["D8"] = D8; pinMap["D9"] = D9; pinMap["D10"] = D10;

Serial.print("pinMap.size() = "); Serial.println(pinMap.size());

The Count is 0. and then Map.h modified below:

  V& operator[](const K& key) {
    MapNode** pp = &head;
    while (*pp != nullptr && (*pp)->key != key) {
      pp = &(*pp)->next;
    }
    if (*pp != nullptr) {
      return (*pp)->value;
    } else {
      MapNode* newNode = new MapNode{ key, V(), nullptr };
      *pp = newNode;
      Count++;
      return newNode->value;
    }
  }

Count++; will fixed the bug.

braydenanderson2014 commented 5 months ago

Issue has now been Patched in latest Platformio Version. Arduino Version to follow. Changes can be found under Development Branch of this Repository. Thank you for informing me of the issue.