 |
- Timestamp:
- 03/21/10 14:15:40
(2 years ago)
- Author:
- kris
- Message:
made the default allocator faster, and hid the implementation from the containers. Use the new cache() method instead for configuring how containers pre-allocate.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r5064 |
r5416 |
|
| 128 | 128 | /*********************************************************************** |
|---|
| 129 | 129 | |
|---|
| 130 | | Return the configured allocator |
|---|
| 131 | | |
|---|
| 132 | | ***********************************************************************/ |
|---|
| 133 | | |
|---|
| 134 | | final Alloc allocator () |
|---|
| 135 | | { |
|---|
| 136 | | return heap; |
|---|
| 137 | | } |
|---|
| 138 | | |
|---|
| 139 | | /*********************************************************************** |
|---|
| 140 | | |
|---|
| 141 | 130 | Return a generic iterator for contained elements |
|---|
| 142 | 131 | |
|---|
| … | … | |
| 169 | 158 | i.node = count ? tree.findFirst(key, cmp, forward) : null; |
|---|
| 170 | 159 | return i; |
|---|
| | 160 | } |
|---|
| | 161 | |
|---|
| | 162 | /*********************************************************************** |
|---|
| | 163 | |
|---|
| | 164 | Configure the assigned allocator with the size of each |
|---|
| | 165 | allocation block (number of nodes allocated at one time) |
|---|
| | 166 | and the number of nodes to pre-populate the cache with. |
|---|
| | 167 | |
|---|
| | 168 | Time complexity: O(n) |
|---|
| | 169 | |
|---|
| | 170 | ***********************************************************************/ |
|---|
| | 171 | |
|---|
| | 172 | final SortedMap cache (size_t chunk, size_t count=0) |
|---|
| | 173 | { |
|---|
| | 174 | heap.config (chunk, count); |
|---|
| | 175 | return this; |
|---|
| 171 | 176 | } |
|---|
| 172 | 177 | |
|---|
| … | … | |
| 1076 | 1081 | // use a chunk allocator, and presize the bucket[] |
|---|
| 1077 | 1082 | auto test = new SortedMap!(int, int, Container.reap, Container.Chunk); |
|---|
| 1078 | | test.allocator.config (1000, 500); |
|---|
| | 1083 | test.cache (1000, 500_000); |
|---|
| 1079 | 1084 | const count = 500_000; |
|---|
| 1080 | 1085 | StopWatch w; |
|---|
Download in other formats:
|
 |
 |
|
 |
Copyright © 2006-2012 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic