| OLD | NEW |
| 1 // Copyright (c) 2003, Google Inc. | 1 // Copyright (c) 2003, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 map.Ensure(elements[i], 1); | 106 map.Ensure(elements[i], 1); |
| 107 map.set(elements[i], (void*)(elements[i]+1)); | 107 map.set(elements[i], (void*)(elements[i]+1)); |
| 108 CHECK_EQ(map.get(elements[i]), (void*)(elements[i]+1)); | 108 CHECK_EQ(map.get(elements[i]), (void*)(elements[i]+1)); |
| 109 } | 109 } |
| 110 for (intptr_t i = 0; i < static_cast<intptr_t>(limit); i++) { | 110 for (intptr_t i = 0; i < static_cast<intptr_t>(limit); i++) { |
| 111 CHECK_EQ(map.get(i), (void*)(i+1)); | 111 CHECK_EQ(map.get(i), (void*)(i+1)); |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 // REQUIRES: BITS==10, i.e., valid range is [0,1023]. | |
| 117 // Representations for different types will end up being: | |
| 118 // PageMap1: array[1024] | |
| 119 // PageMap2: array[32][32] | |
| 120 // PageMap3: array[16][16][4] | |
| 121 template <class Type> | |
| 122 void TestNext(const char* name) { | |
| 123 RAW_LOG(ERROR, "Running NextTest %s\n", name); | |
| 124 Type map(malloc); | |
| 125 char a, b, c, d, e; | |
| 126 | |
| 127 // When map is empty | |
| 128 CHECK(map.Next(0) == NULL); | |
| 129 CHECK(map.Next(5) == NULL); | |
| 130 CHECK(map.Next(1<<30) == NULL); | |
| 131 | |
| 132 // Add a single value | |
| 133 map.Ensure(40, 1); | |
| 134 map.set(40, &a); | |
| 135 CHECK(map.Next(0) == &a); | |
| 136 CHECK(map.Next(39) == &a); | |
| 137 CHECK(map.Next(40) == &a); | |
| 138 CHECK(map.Next(41) == NULL); | |
| 139 CHECK(map.Next(1<<30) == NULL); | |
| 140 | |
| 141 // Add a few values | |
| 142 map.Ensure(41, 1); | |
| 143 map.Ensure(100, 3); | |
| 144 map.set(41, &b); | |
| 145 map.set(100, &c); | |
| 146 map.set(101, &d); | |
| 147 map.set(102, &e); | |
| 148 CHECK(map.Next(0) == &a); | |
| 149 CHECK(map.Next(39) == &a); | |
| 150 CHECK(map.Next(40) == &a); | |
| 151 CHECK(map.Next(41) == &b); | |
| 152 CHECK(map.Next(42) == &c); | |
| 153 CHECK(map.Next(63) == &c); | |
| 154 CHECK(map.Next(64) == &c); | |
| 155 CHECK(map.Next(65) == &c); | |
| 156 CHECK(map.Next(99) == &c); | |
| 157 CHECK(map.Next(100) == &c); | |
| 158 CHECK(map.Next(101) == &d); | |
| 159 CHECK(map.Next(102) == &e); | |
| 160 CHECK(map.Next(103) == NULL); | |
| 161 } | |
| 162 | |
| 163 int main(int argc, char** argv) { | 116 int main(int argc, char** argv) { |
| 164 TestMap< TCMalloc_PageMap1<10> > (100, true); | 117 TestMap< TCMalloc_PageMap1<10> > (100, true); |
| 165 TestMap< TCMalloc_PageMap1<10> > (1 << 10, false); | 118 TestMap< TCMalloc_PageMap1<10> > (1 << 10, false); |
| 166 TestMap< TCMalloc_PageMap2<20> > (100, true); | 119 TestMap< TCMalloc_PageMap2<20> > (100, true); |
| 167 TestMap< TCMalloc_PageMap2<20> > (1 << 20, false); | 120 TestMap< TCMalloc_PageMap2<20> > (1 << 20, false); |
| 168 TestMap< TCMalloc_PageMap3<20> > (100, true); | 121 TestMap< TCMalloc_PageMap3<20> > (100, true); |
| 169 TestMap< TCMalloc_PageMap3<20> > (1 << 20, false); | 122 TestMap< TCMalloc_PageMap3<20> > (1 << 20, false); |
| 170 | 123 |
| 171 TestNext< TCMalloc_PageMap1<10> >("PageMap1"); | |
| 172 TestNext< TCMalloc_PageMap2<10> >("PageMap2"); | |
| 173 TestNext< TCMalloc_PageMap3<10> >("PageMap3"); | |
| 174 | |
| 175 printf("PASS\n"); | 124 printf("PASS\n"); |
| 176 return 0; | 125 return 0; |
| 177 } | 126 } |
| OLD | NEW |