Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of F401RE-USBHost by
mymap.h
00001 #pragma once 00002 00003 template<class K,class T> 00004 class mymap { 00005 struct mypair { 00006 K first; 00007 T second; 00008 }; 00009 public: 00010 mymap() { 00011 m_size = 0; 00012 } 00013 T& operator[](const K& key) { 00014 int it; 00015 if (count(key) == 0) { 00016 it = insert(key, 0); 00017 } else { 00018 it = find(key); 00019 } 00020 return m_buf[it].second; 00021 } 00022 bool empty() { return m_size == 0 ? true : false; } 00023 int size() { return m_size; } 00024 void clear() { m_size = 0; } 00025 int count(K key) { 00026 for(int i = 0; i < m_size; i++) { 00027 if (m_buf[i].first == key) { 00028 return 1; 00029 } 00030 } 00031 return 0; 00032 } 00033 00034 private: 00035 int find(K key) { 00036 for(int i = 0; i < m_size; i++) { 00037 if (m_buf[i].first == key) { 00038 return i; 00039 } 00040 } 00041 return -1; 00042 } 00043 int insert(K key, T value) { 00044 int it = find(key); 00045 if (it != -1) { 00046 m_buf[it].second = value; 00047 return it; 00048 } 00049 mypair* new_buf = new mypair[m_size+1]; 00050 if (m_size > 0) { 00051 for(int i = 0; i < m_size; i++) { 00052 new_buf[i] = m_buf[i]; 00053 } 00054 delete[] m_buf; 00055 } 00056 m_buf = new_buf; 00057 it = m_size++; 00058 m_buf[it].first = key; 00059 m_buf[it].second = value; 00060 return it; 00061 } 00062 00063 int m_size; 00064 mypair *m_buf; 00065 };
Generated on Tue Jul 12 2022 21:43:28 by
1.7.2
