Преглед изворни кода

Perform some cleanup.
Add clang-format.

Sam Jaffe пре 5 година
родитељ
комит
8c840a317e
6 измењених фајлова са 283 додато и 135 уклоњено
  1. 108 0
      .clang-format
  2. 77 53
      trie.hpp
  3. 2 2
      trie.xcodeproj/project.pbxproj
  4. 17 15
      trie_impl.hpp
  5. 43 24
      trie_iterator.hpp
  6. 36 41
      trie_test.cpp

+ 108 - 0
.clang-format

@@ -0,0 +1,108 @@
+---
+Language:        Cpp
+# BasedOnStyle:  LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Right
+AlignOperands:   true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: true
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: true
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:   
+  AfterClass:      false
+  AfterControlStatement: false
+  AfterEnum:       false
+  AfterFunction:   false
+  AfterNamespace:  false
+  AfterObjCDeclaration: false
+  AfterStruct:     false
+  AfterUnion:      false
+  BeforeCatch:     false
+  BeforeElse:      false
+  IndentBraces:    false
+  SplitEmptyFunction: true
+  SplitEmptyRecord: true
+  SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Attach
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeColon
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit:     80
+CommentPragmas:  '^ IWYU pragma:'
+CompactNamespaces: true
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+DisableFormat:   false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+ForEachMacros:   
+  - foreach
+  - Q_FOREACH
+  - BOOST_FOREACH
+IncludeCategories: 
+  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
+    Priority:        2
+  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
+    Priority:        3
+  - Regex:           '.*'
+    Priority:        1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentWidth:     2
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: All
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Middle
+ReflowComments:  true
+SortIncludes:    true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles:  false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard:        Cpp11
+TabWidth:        8
+UseTab:          Never
+...
+

+ 77 - 53
trie.hpp

@@ -12,49 +12,54 @@
 #include "pointers/value_ptr.hpp"
 #include <map>
 
-template <typename K, typename V, typename Compare = std::less<K>>
-class trie;
+template <typename K, typename V, typename Compare = std::less<K>> class trie;
 
 namespace detail {
-  template <typename Trie, typename Iter>
-  class trie_iterator_base;
+  template <typename Trie, typename Iter> class trie_iterator_base;
   template <typename Iter, typename Trie, typename KS>
   Iter find_impl(Trie * tr, KS const & keys);
 }
 
-template <typename Trie, typename Iter>
-class trie_iterator;
-template <typename Trie, typename Iter>
-class trie_reverse_iterator;
+template <typename Trie, typename Iter> class trie_iterator;
+template <typename Trie, typename Iter> class trie_reverse_iterator;
 
-template <typename K, typename V, typename Compare>
-class trie {
+template <typename K, typename V, typename Compare> class trie {
 private:
   using self_t = trie<K, V, Compare>;
-  using layer_t = value_ptr<self_t>;
-  using backing_t = std::map<K, const_propogating_ptr<layer_t>, Compare>;
+  using impl_value_type = const_propogating_ptr<value_ptr<self_t>>;
+  using backing_t = std::map<K, impl_value_type, Compare>;
   template <typename KS>
-  using is_collection_t = typename std::enable_if<std::is_same<K, std::decay_t<decltype(*std::begin(std::declval<KS>()))>>::value>::type;
+  using element_type = std::decay_t<decltype(*std::begin(std::declval<KS>()))>;
+  template <typename KS>
+  using is_collection_t =
+      std::enable_if_t<std::is_same<K, element_type<KS>>::value>;
 
 public:
   using key_type = K;
   using mapped_type = V;
   using key_compare = Compare;
-  
+
   using local_iterator = typename backing_t::iterator;
   using local_const_iterator = typename backing_t::const_iterator;
   using local_reverse_iterator = typename backing_t::reverse_iterator;
-  using local_const_reverse_iterator = typename backing_t::const_reverse_iterator;
-  
+  using local_const_reverse_iterator =
+      typename backing_t::const_reverse_iterator;
+
   using iterator = trie_iterator<self_t, local_iterator>;
   using const_iterator = trie_iterator<self_t const, local_const_iterator>;
   using post_iterator = trie_iterator<self_t, local_reverse_iterator>;
-  using const_post_iterator = trie_iterator<self_t const, local_const_reverse_iterator>;
-  using reverse_iterator = trie_reverse_iterator<self_t, local_reverse_iterator>;
-  using const_reverse_iterator = trie_reverse_iterator<self_t const, local_const_reverse_iterator>;
+  using const_post_iterator =
+      trie_iterator<self_t const, local_const_reverse_iterator>;
+  using reverse_iterator =
+      trie_reverse_iterator<self_t, local_reverse_iterator>;
+  using const_reverse_iterator =
+      trie_reverse_iterator<self_t const, local_const_reverse_iterator>;
+
 private:
   using impl_iterator = detail::trie_iterator_base<self_t, local_iterator>;
-  using impl_const_iterator = detail::trie_iterator_base<self_t const, local_const_iterator>;
+  using impl_const_iterator =
+      detail::trie_iterator_base<self_t const, local_const_iterator>;
+
 public:
   trie() {}
   trie(trie const & other);
@@ -68,7 +73,7 @@ public:
   operator mapped_type const &() const { return value(); }
   mapped_type & value() { return value_; }
   mapped_type const & value() const { return value_; }
-  
+
   template <typename KS, typename = is_collection_t<KS>>
   self_t & operator[](KS const & keys) {
     return *emplace(keys).first.stk.top();
@@ -79,15 +84,17 @@ public:
   self_t & operator[](std::initializer_list<key_type> keys) {
     return operator[]<>(keys);
   }
-  
+
   template <typename KS>
   std::pair<iterator, bool> insert(KS const & keys, mapped_type const & value) {
     return emplace_impl(keys, value);
   }
-  std::pair<iterator, bool> insert(key_type const & key, mapped_type const & value) {
+  std::pair<iterator, bool> insert(key_type const & key,
+                                   mapped_type const & value) {
     return emplace_impl({key}, value);
   }
-  std::pair<iterator, bool> insert(std::initializer_list<key_type> keys, mapped_type const & value) {
+  std::pair<iterator, bool> insert(std::initializer_list<key_type> keys,
+                                   mapped_type const & value) {
     return emplace_impl(keys, value);
   }
   template <typename KS, typename... Args>
@@ -103,10 +110,11 @@ public:
     return emplace_impl({key}, std::forward<Args>(args)...);
   }
   template <typename... Args>
-  std::pair<iterator, bool> emplace(std::initializer_list<key_type> keys, Args &&... args) {
+  std::pair<iterator, bool> emplace(std::initializer_list<key_type> keys,
+                                    Args &&... args) {
     return emplace_impl(keys, std::forward<Args>(args)...);
   }
-  
+
   iterator begin() { return {this}; }
   iterator end() { return {}; }
   const_iterator begin() const { return {this}; }
@@ -119,7 +127,7 @@ public:
   const_reverse_iterator rend() const { return {}; }
   const_reverse_iterator crbegin() const { return rbegin(); }
   const_reverse_iterator crend() const { return rend(); }
-  
+
   local_iterator local_begin() { return impl_.begin(); }
   local_iterator local_end() { return impl_.end(); }
   local_const_iterator local_begin() const { return impl_.begin(); }
@@ -129,58 +137,74 @@ public:
   local_reverse_iterator local_rend() { return impl_.rend(); }
   local_const_reverse_iterator local_rbegin() const { return impl_.rbegin(); }
   local_const_reverse_iterator local_rend() const { return impl_.rend(); }
-  
-  
-  template <typename KS>
-  iterator find(KS const & keys) { return detail::find_impl<impl_iterator>(this, keys); }
-  iterator find(key_type const & key) { return find_impl<impl_iterator>(this, {key}); }
-  iterator find(std::initializer_list<key_type> keys) { return find_impl<impl_iterator>(this, keys); }
-  template <typename KS>
-  const_iterator find(KS const & keys) const { return detail::find_impl<impl_const_iterator>(this, keys); }
-  const_iterator find(key_type const & key) const { return find_impl<impl_const_iterator>(this, {key}); }
-  const_iterator find(std::initializer_list<key_type> keys) const { return find_impl<impl_const_iterator>(this, keys); }
-  
-  template <typename KS>
-  void erase(KS const & keys) { drop(find(keys)); }
+
+  template <typename KS> iterator find(KS const & keys) {
+    return detail::find_impl<impl_iterator>(this, keys);
+  }
+  iterator find(key_type const & key) {
+    return find_impl<impl_iterator>(this, {key});
+  }
+  iterator find(std::initializer_list<key_type> keys) {
+    return find_impl<impl_iterator>(this, keys);
+  }
+  template <typename KS> const_iterator find(KS const & keys) const {
+    return detail::find_impl<impl_const_iterator>(this, keys);
+  }
+  const_iterator find(key_type const & key) const {
+    return find_impl<impl_const_iterator>(this, {key});
+  }
+  const_iterator find(std::initializer_list<key_type> keys) const {
+    return find_impl<impl_const_iterator>(this, keys);
+  }
+
+  template <typename KS> void erase(KS const & keys) { drop(find(keys)); }
   void erase(key_type const & key) { drop(find(key)); }
   void erase(std::initializer_list<key_type> keys) { drop(find(keys)); }
-  
+
   void clear();
+
 private:
   void drop(iterator it);
-  
+
   template <typename Iter, typename Trie, typename KS>
   friend Iter detail::find_impl(Trie * tr, KS const & keys);
   template <typename Iter, typename Trie>
   static Iter find_impl(Trie * tr, std::initializer_list<key_type> keys) {
     return detail::find_impl<Iter>(tr, keys);
   }
-  
+
   template <typename KS, typename... Args>
   std::pair<impl_iterator, bool> emplace_impl(KS && keys, Args &&... args);
   template <typename... Args>
-  std::pair<impl_iterator, bool> emplace_impl(std::initializer_list<key_type> keys, Args &&... args) {
-    return emplace_impl<std::initializer_list<key_type>>(std::move(keys), std::forward<Args>(args)...);
+  std::pair<impl_iterator, bool>
+  emplace_impl(std::initializer_list<key_type> keys, Args &&... args) {
+    return emplace_impl<std::initializer_list<key_type>>(
+        std::move(keys), std::forward<Args>(args)...);
   }
-  
+
   template <typename Key>
   void insert_impl(impl_iterator & out, bool & create, Key && key);
-  
+
   friend bool operator==(trie const & lhs, trie const & rhs) {
-    auto it1 = lhs.begin(), it2 = rhs.begin(), end1 = lhs.end(), end2 = lhs.end();
-    for ( ; it1 != end1 && it2 != end2; ++it1, ++it2 ) {
-      if (!it1.keys.empty() && !it2.keys.empty() && it1.keys.back() != it2.keys.back()) { return false; }
-      else if (it1.root().value_ != it2.root().value_) { return false; }
+    const_iterator it1 = lhs.begin(), it2 = rhs.begin();
+    const_iterator const end1 = lhs.end(), end2 = lhs.end();
+    for (; it1 != end1 && it2 != end2; ++it1, ++it2) {
+      if (!it1.keys.empty() && !it2.keys.empty() &&
+          it1.keys.back() != it2.keys.back()) {
+        return false;
+      } else if (it1.root().value_ != it2.root().value_) {
+        return false;
+      }
     }
     return it1 == end1 && it2 == end2;
   }
-  
+
   friend void swap(trie & lhs, trie & rhs) {
     using std::swap;
     swap(lhs.value_, rhs.value_);
     swap(lhs.impl_, rhs.impl_);
   }
-  
+
   mapped_type value_{};
   backing_t impl_{};
 };

+ 2 - 2
trie.xcodeproj/project.pbxproj

@@ -406,7 +406,7 @@
 				MTL_ENABLE_DEBUG_INFO = YES;
 				ONLY_ACTIVE_ARCH = YES;
 				SDKROOT = macosx;
-				USER_HEADER_SEARCH_PATHS = "../ ../../types";
+				USER_HEADER_SEARCH_PATHS = "../iterator/include/ ../../types";
 			};
 			name = Debug;
 		};
@@ -454,7 +454,7 @@
 				MACOSX_DEPLOYMENT_TARGET = 10.10;
 				MTL_ENABLE_DEBUG_INFO = NO;
 				SDKROOT = macosx;
-				USER_HEADER_SEARCH_PATHS = "../ ../../types";
+				USER_HEADER_SEARCH_PATHS = "../iterator/include/ ../../types";
 			};
 			name = Release;
 		};

+ 17 - 15
trie_impl.hpp

@@ -17,8 +17,10 @@
 template <typename K, typename V, typename C>
 trie<K, V, C>::trie(trie const & other) : value_(other.value_) {
   impl_iterator current{this};
-  for (const_iterator it = ++const_iterator{&other}, end = {}; it != end; ++it) {
-    while (current.keys.size() >= it.keys.size()) { current.pop(); }
+  for (const_iterator it = ++other.begin(), end = {}; it != end; ++it) {
+    while (current.keys.size() >= it.keys.size()) {
+      current.pop();
+    }
     auto tmp = current.root().insert(it.keys.back(), *it).first;
     current.push(tmp.iters.top());
   }
@@ -48,13 +50,14 @@ auto trie<K, V, C>::operator=(trie && other) -> self_t & {
 // Operations: O(log(n)/d)
 template <typename K, typename V, typename C>
 template <typename Key>
-void trie<K, V, C>::insert_impl(impl_iterator & out, bool & create, Key && key) {
+void trie<K, V, C>::insert_impl(impl_iterator & out, bool & create,
+                                Key && key) {
   auto it = impl_.lower_bound(key);
-  if ( it == impl_.end() || key_compare()(key, it->first) ) {
+  if (it == impl_.end() || key_compare()(key, it->first)) {
     create = true;
     it = impl_.emplace_hint(it, key, make_value<self_t>());
   }
-  out.push({ it, impl_.end() });
+  out.push({it, impl_.end()});
 }
 
 // n := total elements
@@ -62,25 +65,24 @@ void trie<K, V, C>::insert_impl(impl_iterator & out, bool & create, Key && key)
 // Operations: O(log(n))
 template <typename K, typename V, typename C>
 template <typename KS, typename... Args>
-auto trie<K, V, C>::emplace_impl(KS && keys, Args &&... args) -> std::pair<impl_iterator, bool> {
+auto trie<K, V, C>::emplace_impl(KS && keys, Args &&... args)
+    -> std::pair<impl_iterator, bool> {
   impl_iterator it{this};
   bool create{false};
-  for ( auto && key : keys ) {
+  for (auto && key : keys) {
     it.root().insert_impl(it, create, std::forward<decltype(key)>(key));
   }
-  if (create) {
-    it.root().value_ = { std::forward<Args>(args)... };
-  }
-  return { std::move(it) , create };
+  if (create) { it.root().value_ = {std::forward<Args>(args)...}; }
+  return {std::move(it), create};
 }
 
 // n := total elements
 // d := average depth
 // Stack: O(1)
 // Operations: O(n)
-template <typename K, typename V, typename C>
-void trie<K, V, C>::clear() {
-  for (reverse_iterator it = rbegin(), end = rend(); it != end && !it.iters.empty(); ++it) {
+template <typename K, typename V, typename C> void trie<K, V, C>::clear() {
+  for (reverse_iterator it = rbegin(), end = rend();
+       it != end && !it.iters.empty(); ++it) {
     auto ptr = std::move(it.iters.top()->second);
     ptr->impl_.clear();
   }
@@ -106,7 +108,7 @@ namespace detail {
     for (auto & key : keys) {
       auto & top = rval.root().impl_;
       auto it = top.find(key), end = top.end();
-      if ( it == end ) { return {}; }
+      if (it == end) { return {}; }
       rval.push({it, end});
     }
     return rval;

+ 43 - 24
trie_iterator.hpp

@@ -14,11 +14,10 @@
 #include <stack>
 
 namespace detail {
-  template <typename Iter>
-  struct trie_iterator_next {
+  template <typename Iter> struct trie_iterator_next {
     using iter_t = ::iterator::end_aware_iterator<Iter>;
     template <typename Trie> iter_t operator()(Trie & tr) {
-      return { tr.local_begin(), tr.local_end() };
+      return {tr.local_begin(), tr.local_end()};
     }
   };
 
@@ -26,12 +25,11 @@ namespace detail {
   struct trie_iterator_next<std::reverse_iterator<Iter>> {
     using iter_t = ::iterator::end_aware_iterator<std::reverse_iterator<Iter>>;
     template <typename Trie> iter_t operator()(Trie & tr) {
-      return { tr.local_rbegin(), tr.local_rend() };
+      return {tr.local_rbegin(), tr.local_rend()};
     }
   };
-  
-  template <typename Trie, typename Iter>
-  class trie_iterator_base {
+
+  template <typename Trie, typename Iter> class trie_iterator_base {
   protected:
     using helper = trie_iterator_next<Iter>;
     using impl_t = typename helper::iter_t;
@@ -39,19 +37,23 @@ namespace detail {
     std::list<typename Trie::key_type> keys;
     std::stack<impl_t> iters;
     bool done{false};
+
   public:
     using reference = decltype(std::declval<Trie>().value());
     using value_type = std::remove_reference_t<reference>;
     using pointer = value_type *;
     using difference_type = std::ptrdiff_t;
     using iterator_category = std::forward_iterator_tag;
+
   public:
     trie_iterator_base() : done{true} {}
     trie_iterator_base(Trie * tr) { stk.push(tr); }
     auto operator*() const -> reference { return root(); }
-    auto operator->() const -> pointer { return std::addressof(operator*()); }
+    auto operator-> () const -> pointer { return std::addressof(operator*()); }
     Trie & root() const {
-      if (stk.empty()) throw std::runtime_error("Dereferencing invalid iterator");
+      if (stk.empty()) {
+        throw std::runtime_error("Dereferencing invalid iterator");
+      }
       return *stk.top();
     }
     trie_iterator_base parent() const {
@@ -59,9 +61,13 @@ namespace detail {
       tmp.pop();
       return tmp;
     }
+
   protected:
     void push(impl_t it) {
-      if (it.done()) { done = true; return; }
+      if (it.done()) {
+        done = true;
+        return;
+      }
       iters.push(it);
       keys.push_back(it->first);
       stk.push(it->second.get());
@@ -84,14 +90,14 @@ namespace detail {
     bool can_recurse() { return !next().done(); }
     void recurse() { push(next()); }
     impl_t next() { return helper()(root()); }
-    friend bool operator!=(trie_iterator_base const & lhs, trie_iterator_base const & rhs) {
+    friend bool operator!=(trie_iterator_base const & lhs,
+                           trie_iterator_base const & rhs) {
       return !(lhs == rhs);
     }
-    friend bool operator==(trie_iterator_base const & lhs, trie_iterator_base const & rhs) {
-      if ( lhs.done && rhs.done ) return true;
-      else if (lhs.keys != rhs.keys) return false;
-      else if ( lhs.done != rhs.done ) return false;
-      else return *lhs == *rhs;
+    friend bool operator==(trie_iterator_base const & lhs,
+                           trie_iterator_base const & rhs) {
+      return (lhs.done && rhs.done) ||
+             (lhs.keys == rhs.keys && lhs.done == rhs.done && *lhs == *rhs);
     }
     friend Trie;
     template <typename Self, typename _Trie, typename KS>
@@ -103,16 +109,21 @@ template <typename Trie, typename Iter>
 class trie_iterator : public detail::trie_iterator_base<Trie, Iter> {
 private:
   using super = detail::trie_iterator_base<Trie, Iter>;
+
 public:
   trie_iterator() : super() {}
-  trie_iterator(Trie * tr) : super(tr) { }
-  trie_iterator(super && take) : super(std::move(take)) { }
+  trie_iterator(Trie * tr) : super(tr) {}
+  trie_iterator(super && take) : super(std::move(take)) {}
   trie_iterator & operator++() {
     if (super::done) return *this;
-    if ( super::iters.empty() || super::can_recurse() ) { super::recurse(); }
-    else { advance(); }
+    if (super::iters.empty() || super::can_recurse()) {
+      super::recurse();
+    } else {
+      advance();
+    }
     return *this;
   }
+
 private:
   void advance() {
     ++super::iters.top();
@@ -129,24 +140,32 @@ template <typename Trie, typename Iter>
 class trie_reverse_iterator : public detail::trie_iterator_base<Trie, Iter> {
 private:
   using super = detail::trie_iterator_base<Trie, Iter>;
+
 public:
   trie_reverse_iterator() : super() {}
   trie_reverse_iterator(Trie * tr) : super(tr) {
     if (super::can_recurse()) recurse();
   }
   trie_reverse_iterator & operator++() {
-    if (super::done || super::iters.empty()) { super::done = true; }
-    else { advance(); }
+    if (super::done || super::iters.empty()) {
+      super::done = true;
+    } else {
+      advance();
+    }
     return *this;
   }
+
 private:
   void recurse() {
-    do { super::recurse(); } while ( super::can_recurse() );
+    do {
+      super::recurse();
+    } while (super::can_recurse());
   }
   void advance() {
     ++super::iters.top();
     if (super::iters.top().done()) {
-      while (super::poping_empty());
+      while (super::poping_empty())
+        ;
       super::assign();
     } else {
       super::assign();

+ 36 - 41
trie_test.cpp

@@ -5,39 +5,34 @@
 //  Created by Sam Jaffe on 6/2/18.
 //
 
-#include <gtest/gtest.h>
 #include <gmock/gmock.h>
+#include <gtest/gtest.h>
 
 #include "trie.hpp"
 
-using Tree = trie<int, int>;
-
 class TrieTest : public ::testing::Test {
 protected:
   virtual void SetUp() override;
   virtual void TearDown() override;
 
-  Tree data;
+  trie<int, int> data;
 };
 
 void TrieTest::SetUp() {
-  data          = 1;
-  data[0      ] = 5;
-  data[{0,1}  ] = 4;
-  data[{0,1,0}] = 3;
-  data[{0,1,2}] = 6;
-  data[{0,2,0}] = 7;
-  data[ 1     ] = 2;
-  data[{1,1}  ] = 8;
-  data[{1,1,0}] = 9;
+  data = 1;
+  data[0] = 5;
+  data[{0, 1}] = 4;
+  data[{0, 1, 0}] = 3;
+  data[{0, 1, 2}] = 6;
+  data[{0, 2, 0}] = 7;
+  data[1] = 2;
+  data[{1, 1}] = 8;
+  data[{1, 1, 0}] = 9;
 }
 
-void TrieTest::TearDown() {
-  data.clear();
-}
+void TrieTest::TearDown() { data.clear(); }
 
-template <typename Iter>
-std::vector<int> flatten(Iter it) {
+template <typename Iter> std::vector<int> flatten(Iter it) {
   decltype(it) end{};
   std::vector<int> out;
   out.reserve(size_t(std::distance(it, end)));
@@ -46,17 +41,17 @@ std::vector<int> flatten(Iter it) {
 }
 
 TEST_F(TrieTest, DefaultConstructorHasNoElementsExceptRoot) {
-  Tree empty;
+  trie<int, int> empty;
   EXPECT_THAT(flatten(empty.cbegin()), std::vector<int>{0});
 }
 
 TEST_F(TrieTest, MoveConstructorIsDestructive) {
-  Tree moved = std::move(data);
+  trie<int, int> moved = std::move(data);
   EXPECT_THAT(flatten(data.cbegin()), std::vector<int>{0});
 }
 
 TEST_F(TrieTest, MoveAssignmentOverwritesAnfRelocates) {
-  Tree value;
+  trie<int, int> value;
   value[2] = 1;
   value = std::move(data);
   EXPECT_THAT(value.find(2), value.end());
@@ -64,76 +59,76 @@ TEST_F(TrieTest, MoveAssignmentOverwritesAnfRelocates) {
 }
 
 TEST_F(TrieTest, CopyConstructorIsDeep) {
-  Tree copy = data;
+  trie<int, int> copy = data;
   copy[{0, 1}] += 1;
   EXPECT_THAT(copy, ::testing::Not(::testing::Eq(data)));
 }
 
 TEST_F(TrieTest, CopyAssignmentOverwritesData) {
-  Tree value;
+  trie<int, int> value;
   value[2] = 1;
   value = data;
   EXPECT_THAT(value, data);
 }
 
 TEST_F(TrieTest, EqualityIsPathSensitive) {
-  Tree t1, t2;
+  trie<int, int> t1, t2;
   t1[1] = 1;
   t2[2] = 1;
-  EXPECT_THAT(flatten(t1.cbegin()),
-              flatten(t2.cbegin()));
+  EXPECT_THAT(flatten(t1.cbegin()), flatten(t2.cbegin()));
   EXPECT_THAT(t1, ::testing::Not(::testing::Eq(t2)));
 }
 
 TEST_F(TrieTest, NormalIterationIsPreOrdered) {
   EXPECT_THAT(flatten(data.cbegin()),
-              std::vector<int>({ 1, 5, 4, 3, 6, 0, 7, 2, 8, 9 }));
+              std::vector<int>({1, 5, 4, 3, 6, 0, 7, 2, 8, 9}));
 }
 
 TEST_F(TrieTest, PostIteratorUsesPostOrder) {
-  EXPECT_THAT(flatten(Tree::const_post_iterator(&data)),
-              std::vector<int>({ 1, 2, 8, 9, 5, 0, 7, 4, 6, 3 }));
+  EXPECT_THAT(flatten(trie<int, int>::const_post_iterator(&data)),
+              std::vector<int>({1, 2, 8, 9, 5, 0, 7, 4, 6, 3}));
 }
 
 TEST_F(TrieTest, ReverseIterationIsBackwardsPreOrdered) {
   EXPECT_THAT(flatten(data.crbegin()),
-              std::vector<int>({ 9, 8, 2, 7, 0, 6, 3, 4, 5, 1 }));
+              std::vector<int>({9, 8, 2, 7, 0, 6, 3, 4, 5, 1}));
 }
 
 TEST_F(TrieTest, InsertingNewElementReturnsSuccess) {
-  Tree example;
-  std::pair<Tree::iterator, bool> rval = example.insert(1, 2);
+  trie<int, int> example;
+  std::pair<trie<int, int>::iterator, bool> rval = example.insert(1, 2);
   EXPECT_TRUE(rval.second);
   EXPECT_THAT(*rval.first, 2);
 }
 
 TEST_F(TrieTest, EmplacingNewElementReturnsSuccess) {
-  Tree example;
-  std::pair<Tree::iterator, bool> rval = example.emplace(1, 2);
+  trie<int, int> example;
+  std::pair<trie<int, int>::iterator, bool> rval = example.emplace(1, 2);
   EXPECT_TRUE(rval.second);
   EXPECT_THAT(*rval.first, 2);
 }
 
 TEST_F(TrieTest, InsertingWithPathWillCreateParents) {
-  Tree example;
-  std::pair<Tree::iterator, bool> rval = example.emplace({1,1,1}, 2);
+  trie<int, int> example;
+  std::pair<trie<int, int>::iterator, bool> rval =
+      example.emplace({1, 1, 1}, 2);
   EXPECT_TRUE(rval.second);
   EXPECT_THAT(*rval.first, 2);
   EXPECT_THAT(example[1][1][1].value(), 2);
 }
 
 TEST_F(TrieTest, InsertingInAlreadyExistantPathNonDestructive) {
-  Tree example;
+  trie<int, int> example;
   example.insert(1, 2);
-  std::pair<Tree::iterator, bool> rval = example.insert(1, 0);
+  std::pair<trie<int, int>::iterator, bool> rval = example.insert(1, 0);
   EXPECT_FALSE(rval.second);
   EXPECT_THAT(*rval.first, ::testing::Not(0));
 }
 
 TEST_F(TrieTest, EmplacingInAlreadyExistantPathNonDestructive) {
-  Tree example;
+  trie<int, int> example;
   example.insert(1, 2);
-  std::pair<Tree::iterator, bool> rval = example.emplace(1, 0);
+  std::pair<trie<int, int>::iterator, bool> rval = example.emplace(1, 0);
   EXPECT_FALSE(rval.second);
   EXPECT_THAT(*rval.first, ::testing::Not(0));
 }
@@ -158,7 +153,7 @@ TEST_F(TrieTest, EraseDropsWholeBranch) {
 }
 
 TEST_F(TrieTest, EraseNonExistentElementIsNoOp) {
-  Tree copy = data;
+  trie<int, int> copy = data;
   copy.erase(-1);
   EXPECT_THAT(copy, data);
 }