Changeset 5c14030 for src/Common
- Timestamp:
- Jul 11, 2018, 4:26:22 PM (6 years ago)
- Branches:
- new-env
- Children:
- d318a18
- Parents:
- 184557e
- git-author:
- Aaron Moss <a3moss@…> (07/11/18 16:10:36)
- git-committer:
- Aaron Moss <a3moss@…> (07/11/18 16:26:22)
- Location:
- src/Common
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/GC.h
r184557e r5c14030 69 69 bool mark; ///< The current collection's mark bit 70 70 unsigned g; ///< The current number generation in use 71 72 /// Trace a traceable object (enabled by SFINAE) 73 template<typename T> 74 static inline auto do_trace(const GC& gc, T& obj, int) -> decltype(gc << obj, void()) { 75 gc << obj; 76 } 77 78 /// Do not trace an untraceable object 79 template<typename T> 80 static inline auto do_trace(const GC&, T&, long) -> void {} 81 82 /// Base case for maybe_trace 83 void maybe_trace() const {} 84 85 public: 86 /// Trace any objects that are traceable 87 template<typename T, typename... Args> 88 void maybe_trace(T& obj, Args&... args) const { 89 // uses SFINAE trick to select proper overload; prefers actually tracing version 90 // (because of int->long conversion), but will fall back to non-tracing 91 do_trace(*this, obj, 0); 92 maybe_trace(args...); 93 } 71 94 }; 72 95 -
src/Common/PersistentDisjointSet.h
r184557e r5c14030 129 129 } 130 130 131 /// reset as base 132 void reset_as_base() { 133 assertf( mode == BASE, "can only reset_as_base() on BASE" ); 134 as<Base>().~Base(); 135 } 136 131 137 /// Non-initializing constructor; should call init() before use 132 138 PersistentDisjointSet( Mode m ) : data(), mode(m) {} … … 165 171 case BASE: { 166 172 for (const auto& entry : as<Base>()) { 167 gc << entry.first;173 gc.maybe_trace( entry.first ); 168 174 } 169 175 return; … … 171 177 case ADD: case REM: { 172 178 const Add& self = as<Add>(); 173 gc << self.base << self.root; 179 gc << self.base; 180 gc.maybe_trace( self.root ); 174 181 return; 175 182 } 176 183 case ADDTO: case REMFROM: { 177 184 const AddTo& self = as<AddTo>(); 178 gc << self.base << self.root << self.child; 185 gc << self.base; 186 gc.maybe_trace( self.root, self.child ); 179 187 return; 180 188 } … … 210 218 // take map out of base 211 219 Base base_map = base->take_as<Base>(); 212 base->reset ();220 base->reset_as_base(); 213 221 214 222 // switch base to inverse of self and mutate base map … … 331 339 // transfer map to new node 332 340 Self* ret = new Self{ BASE, take_as<Base>() }; 333 reset ();341 reset_as_base(); 334 342 335 343 // set self to REM node … … 352 360 // transfer map to new node 353 361 Self* ret = new Self{ BASE, take_as<Base>() }; 354 reset ();362 reset_as_base(); 355 363 356 364 // find set nodes … … 449 457 /// `f` should take members by const reference or copy 450 458 template<typename F> 451 void apply_to_class(Elm i, F&& f) const {459 void for_class(Elm i, F&& f) const { 452 460 const Base& self = rerooted(); 453 461 -
src/Common/PersistentMap.h
r184557e r5c14030 139 139 case BASE: { 140 140 for (const auto& entry : as<Base>()) { 141 gc << entry.first << entry.second;141 gc.maybe_trace( entry.first, entry.second ); 142 142 } 143 143 return; … … 145 145 case REM: { 146 146 const Rem& self = as<Rem>(); 147 gc << self.base << self.key; 147 gc << self.base; 148 gc.maybe_trace( self.key ); 148 149 return; 149 150 } 150 151 case INS: case UPD: { 151 152 const Ins& self = as<Ins>(); 152 gc << self.base << self.key << self.val; 153 gc << self.base; 154 gc.maybe_trace( self.key, self.val ); 153 155 return; 154 156 } … … 424 426 } 425 427 428 /// Applies the function `f` to all elements of the map. 429 /// `f` should take two parameters, `const Key&` and `const Val&`. 430 template<typename F> 431 void for_each(F&& f) const { 432 for ( const auto& entry : rerooted() ) { f( entry.first, entry.second ); } 433 } 434 426 435 /// Applies the function `f` to all elements of the map, returning a pointer to the updated map. 427 436 /// `f` should take two parameters, `const Key&` and `Val&`, returning option<Val> filled with … … 429 438 /// NOTE: when porting to C++17, this should work fine with std::optional 430 439 template<typename F> 431 Self* apply_to_all(F&& f) {440 Self* mutate_each(F&& f) { 432 441 // reset to root and exit early if no change 433 442 if ( rerooted().empty() ) return this; … … 454 463 return next_edit; 455 464 } 456 457 /// Applies the function `f` to all elements of the map.458 /// `f` should take two parameters, `const Key&` and `const Val&`.459 template<typename F>460 void apply_to_all(F&& f) const {461 for ( const auto& entry : rerooted() ) { f( entry.first, entry.second ); }462 }463 465 }; 464 466 -
src/Common/option.h
r184557e r5c14030 16 16 #pragma once 17 17 18 #include <cassert> 18 19 #include <functional> 19 20 #include <type_traits> 20 21 #include <utility> 21 22 #include "debug.h"23 22 24 23 using std::move; … … 121 120 122 121 /// Get contained value (checked) 123 T& value() & { ass ume(filled, "checked get failed"); return get(); }124 const T& value() const& { ass ume(filled, "checked get failed"); return get(); }125 T&& value() && { ass ume(filled, "checked get failed"); return move(get()); }126 const T&& value() const&& { ass ume(filled, "checked get failed"); return move(get()); }122 T& value() & { assertf(filled, "checked get failed"); return get(); } 123 const T& value() const& { assertf(filled, "checked get failed"); return get(); } 124 T&& value() && { assertf(filled, "checked get failed"); return move(get()); } 125 const T&& value() const&& { assertf(filled, "checked get failed"); return move(get()); } 127 126 128 127 /// Get contained or default value
Note: See TracChangeset
for help on using the changeset viewer.