Advertisement
bobmarley12345

C map test

Jan 28th, 2023
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.84 KB | None | 0 0
  1. static hash_t myHashFunc(const void* key) {
  2.     return (int) key;
  3. }
  4.  
  5. int main() {
  6.     // maps::OLD_ArrayMap<int, int> map = maps::OLD_ArrayMap<int, int>();
  7.     // map.put(25, 69);
  8.     // map.put(50, 420);
  9.     // map.put(150, 1337);
  10.     // // tests
  11.     // for (maps::Node<int, int>& node : map) {
  12.     //     std::cout << "Key(" << node.mKey << ") = " << node.mVal << std::endl;
  13.     // }
  14.     // std::cout << "Removing 50..." << std::endl;
  15.     // map.remove(50);
  16.     // for (maps::Node<int, int>& node : map) {
  17.     //     std::cout << "Key(" << node.mKey << ") = " << node.mVal << std::endl;
  18.     // }
  19.     // std::cout << "Replacing key 25 with value 2020..." << std::endl;
  20.     // map.put(25, 2020);
  21.     // for (maps::Node<int, int>& node : map) {
  22.     //     std::cout << "Key(" << node.mKey << ") = " << node.mVal << std::endl;
  23.     // }
  24.  
  25.     ArrayMap* map = new_array_map(myHashFunc);
  26.     arraymap_put(map, (void*) 25, (void*) 69);
  27.     arraymap_put(map, (void*) 50, (void*) 420);
  28.     arraymap_put(map, (void*) 150, (void*) 1337);
  29.  
  30.     // tests
  31.  
  32.     for (int i = 0; i < map->m_tab_len; i++) {
  33.         ArrayMapNode node = map->m_tab[i];
  34.         std::cout << "Key(" << (int) node.m_key << ") = " << (int) node.m_val << std::endl;
  35.     }
  36.  
  37.     std::cout << "Removing 50..." << std::endl;
  38.     arraymap_remove(map, (void*) 50);
  39.  
  40.     for (int i = 0; i < map->m_tab_len; i++) {
  41.         ArrayMapNode node = map->m_tab[i];
  42.         std::cout << "Key(" << (int) node.m_key << ") = " << (int) node.m_val << std::endl;
  43.     }
  44.  
  45.     std::cout << "Replacing key 25 with value 2020..." << std::endl;
  46.     arraymap_put(map, (void*) 25, (void*) 2020);
  47.  
  48.     for (int i = 0; i < map->m_tab_len; i++) {
  49.         ArrayMapNode node = map->m_tab[i];
  50.         std::cout << "Key(" << (int) node.m_key << ") = " << (int) node.m_val << std::endl;
  51.     }
  52.  
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement