OLD | NEW |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 #ifndef SRC_VM_VECTOR_H_ | 5 #ifndef SRC_VM_VECTOR_H_ |
6 #define SRC_VM_VECTOR_H_ | 6 #define SRC_VM_VECTOR_H_ |
7 | 7 |
8 #include "src/shared/assert.h" | 8 #include "src/shared/assert.h" |
9 | 9 |
10 #include "src/vm/sort.h" | 10 #include "src/vm/sort.h" |
11 | 11 |
12 namespace fletch { | 12 namespace dartino { |
13 | 13 |
14 extern uint8* DoubleSize(size_t capacity, uint8* backing); | 14 extern uint8* DoubleSize(size_t capacity, uint8* backing); |
15 | 15 |
16 template <typename T> | 16 template <typename T> |
17 class Vector { | 17 class Vector { |
18 public: | 18 public: |
19 typedef T ValueType; | 19 typedef T ValueType; |
20 typedef T& Reference; | 20 typedef T& Reference; |
21 typedef const T& ConstReference; | 21 typedef const T& ConstReference; |
22 typedef size_t SizeType; | 22 typedef size_t SizeType; |
(...skipping 25 matching lines...) Expand all Loading... |
48 | 48 |
49 Reference Back() { return At(size() - 1); } | 49 Reference Back() { return At(size() - 1); } |
50 | 50 |
51 ConstReference Back() const { return At(size() - 1); } | 51 ConstReference Back() const { return At(size() - 1); } |
52 | 52 |
53 T* Data() { return backing_; } | 53 T* Data() { return backing_; } |
54 | 54 |
55 const T* Data() const { return backing_; } | 55 const T* Data() const { return backing_; } |
56 | 56 |
57 void Sort(typename SortType<T>::Compare compare) { | 57 void Sort(typename SortType<T>::Compare compare) { |
58 fletch::Sort<T>(backing_, size_, compare); | 58 dartino::Sort<T>(backing_, size_, compare); |
59 } | 59 } |
60 | 60 |
61 void Sort(typename SortType<T>::PointerCompare compare) { | 61 void Sort(typename SortType<T>::PointerCompare compare) { |
62 fletch::Sort<T>(backing_, size_, compare); | 62 dartino::Sort<T>(backing_, size_, compare); |
63 } | 63 } |
64 | 64 |
65 void Sort(typename SortType<T>::Compare compare, size_t start, size_t end) { | 65 void Sort(typename SortType<T>::Compare compare, size_t start, size_t end) { |
66 fletch::Sort<T>(backing_ + start, end, compare); | 66 dartino::Sort<T>(backing_ + start, end, compare); |
67 } | 67 } |
68 | 68 |
69 void Sort(typename SortType<T>::PointerCompare compare, size_t start, | 69 void Sort(typename SortType<T>::PointerCompare compare, size_t start, |
70 size_t end) { | 70 size_t end) { |
71 fletch::Sort<T>(backing_ + start, end, compare); | 71 dartino::Sort<T>(backing_ + start, end, compare); |
72 } | 72 } |
73 | 73 |
74 void Swap(Vector& other) { | 74 void Swap(Vector& other) { |
75 T* t = backing_; | 75 T* t = backing_; |
76 backing_ = other.backing_; | 76 backing_ = other.backing_; |
77 other.backing_ = t; | 77 other.backing_ = t; |
78 SizeType t2 = size_; | 78 SizeType t2 = size_; |
79 size_ = other.size_; | 79 size_ = other.size_; |
80 other.size_ = t2; | 80 other.size_ = t2; |
81 t2 = capacity_; | 81 t2 = capacity_; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 backing_ = reinterpret_cast<T*>( | 144 backing_ = reinterpret_cast<T*>( |
145 DoubleSize(capacity_ * sizeof(T), reinterpret_cast<uint8*>(backing_))); | 145 DoubleSize(capacity_ * sizeof(T), reinterpret_cast<uint8*>(backing_))); |
146 capacity_ *= 2; | 146 capacity_ *= 2; |
147 } | 147 } |
148 | 148 |
149 T* backing_; | 149 T* backing_; |
150 size_t size_; | 150 size_t size_; |
151 size_t capacity_; | 151 size_t capacity_; |
152 }; | 152 }; |
153 | 153 |
154 } // namespace fletch | 154 } // namespace dartino |
155 | 155 |
156 #endif // SRC_VM_VECTOR_H_ | 156 #endif // SRC_VM_VECTOR_H_ |
OLD | NEW |