mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Create a Dictionary abstraction over the raw Cons list. (#327)
* Create a Dictionary abstraction over the raw Cons list. * renamed Cons and some methods of Dictionary, various other cleanup
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
|
||||
#include "executable_semantics/interpreter/list_node.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
/// A persistent stack data structure.
|
||||
@@ -24,7 +26,7 @@ struct Stack {
|
||||
using reference = const T&;
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
|
||||
Iterator(Cons<T>* x) : p(x) {}
|
||||
Iterator(ListNode<T>* x) : p(x) {}
|
||||
Iterator(const Iterator& mit) : p(mit.p) {}
|
||||
Iterator& operator++() {
|
||||
p = p->next;
|
||||
@@ -41,7 +43,7 @@ struct Stack {
|
||||
const T* operator->() { return &p->curr; }
|
||||
|
||||
private:
|
||||
Cons<T>* p;
|
||||
ListNode<T>* p;
|
||||
};
|
||||
|
||||
/// The position of the first/`Top()` element, or `end()` if
|
||||
@@ -58,7 +60,7 @@ struct Stack {
|
||||
Stack(T x) : Stack() { Push(x); }
|
||||
|
||||
/// Pushes `x` onto the top of the stack.
|
||||
void Push(T x) { head = new Cons<T>(x, head); }
|
||||
void Push(T x) { head = new ListNode<T>(x, head); }
|
||||
|
||||
/// Returns a copy of `*this`, with `x` pushed onto the top.
|
||||
auto Pushing(T x) const -> Stack {
|
||||
@@ -128,7 +130,7 @@ struct Stack {
|
||||
|
||||
private:
|
||||
/// An linked list of cells containing the elements of self.
|
||||
Cons<T>* head;
|
||||
ListNode<T>* head;
|
||||
};
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
Reference in New Issue
Block a user