Skip to content

Commit

Permalink
Almost Completed SeparateChainingHashTable with test.
Browse files Browse the repository at this point in the history
Todo: different hash functions.
Restructured Iterator and Node inheritance hierarchy.
  • Loading branch information
saad0105050 committed Sep 13, 2014
1 parent b8fbafd commit 8e00e2a
Show file tree
Hide file tree
Showing 9 changed files with 625 additions and 156 deletions.
1 change: 1 addition & 0 deletions YASI_12/YASI_12.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<ClInclude Include="ds.iterator.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="ds.iterator_test.h" />
<ClInclude Include="ds.kvpair.h" />
<ClInclude Include="ds.list.h" />
<ClInclude Include="ds.node.h" />
Expand Down
3 changes: 3 additions & 0 deletions YASI_12/YASI_12.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,8 @@
<ClInclude Include="ds.hashtable.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ds.iterator_test.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
10 changes: 5 additions & 5 deletions YASI_12/ds.binarytreebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ namespace yasi{

// inorder iterator
template< class E, class Node>
class InorderBinaryTreeIterator : public NodeIterator<E, Node>{
class InorderBinaryTreeIterator : public ForwardNodeIterator<E, Node, InorderBinaryTreeIterator<E,Node>>{
typedef InorderBinaryTreeIterator<E, Node> self;
typedef NodeIterator<E, Node> base;
typedef ForwardNodeIterator<E, Node, InorderBinaryTreeIterator<E, Node>> base;
protected:
BinaryTreeBase<E, Node>* t;
public:
Expand All @@ -278,9 +278,9 @@ namespace yasi{
InorderBinaryTreeIterator(const BinaryTreeBase* t, Node* pNode) : base(pNode), t(t){}
InorderBinaryTreeIterator(const self& other) : base(other.pNode), t(other.t){}
// operators
self& operator ++ ()/*prefix*/{ pNode = t->inorderSuccessor(pNode); return *this; }
self operator ++ (int)/*postfix*/{ self temp = *this; pNode = t->inorderSuccessor(pNode); return temp; }
self& operator = (const self& other){ this->pNode = other.pNode; this->t = other.t; *this; }
virtual self& operator ++ ()/*prefix*/{ pNode = t->inorderSuccessor(pNode); return *this; }
virtual self operator ++ (int)/*postfix*/{ self temp = *this; pNode = t->inorderSuccessor(pNode); return temp; }
virtual self& operator = (const self& other){ this->pNode = other.pNode; this->t = other.t; *this; }
};

} // namespace ds
Expand Down
60 changes: 14 additions & 46 deletions YASI_12/ds.doublylinkedlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,6 @@ using namespace std;
namespace yasi{
namespace ds{

template< class E, class Node>
class DListNodeBase : public virtual ListNodeBase<E, Node>{
typedef Node node_t;
protected:
node_t* pPrev;
public:
DListNodeBase(): pPrev(NULL) { }
DListNodeBase(const E& e) : ListNodeBase<E, Node>(e), pPrev(NULL) {}
virtual ~DListNodeBase(){ pPrev = NULL; }
virtual node_t* prev(){ return pPrev; }
virtual void setPrev(node_t* pNode){ pPrev = pNode; }
};

template<class E>
class DListNode : public virtual DListNodeBase< E, DListNode<E> >{
typedef DListNode<E> node;
public:
virtual ~DListNode(){
pPrev = pNext = NULL;
}
DListNode(){}
// because of virtual inheritance, we need to initialize
// all virtual base constructors from here
DListNode(const E& elem): DListNodeBase<E, DListNode<E> >(elem), NodeBase<E>(elem){}
// to be in sync with ListNode class
DListNode(const E& elem, node* pNext) : DListNodeBase<E, DListNode<E> >(elem), NodeBase<E>(elem){
this->pNext = pNext;
}
DListNode(
const E& elem,
node* pNext,
node* pPrev) :
NodeBase<E>(elem),
DListNodeBase<E, DListNode<E> >(elem){
this->pNext = pNext;
this->pPrev = pPrev;
}
};

// doubly linked list interface
template<class E, class Node, class Iter = DLLIterator<E,Node> >
Expand All @@ -64,18 +26,20 @@ namespace ds{

// doubly linked list iterator
template<class E, class Node>
class DLLIterator : public SLLIterator< E, Node > {
class DLLIterator : public virtual BidirectionalNodeIterator< E, Node, DLLIterator<E,Node> > {
typedef DLLIterator<E, Node> self;
typedef SLLIterator<E, Node> base;
typedef BidirectionalNodeIterator< E, Node, DLLIterator<E, Node> > base;
public:
virtual ~DLLIterator(){}
DLLIterator() {}
DLLIterator(Node* pNode) : base(pNode){}
DLLIterator(const self& other) : base(other.pNode){}
// operators
self& operator -- ()/*prefix*/{ pNode = pNode->prev(); return *this; }
self operator -- (int)/*postfix*/{ self temp = *this; pNode = pNode->prev(); return temp; }
self& operator = (const self& other){ this->pNode = other.pNode; return *this; }
DLLIterator(Node* pNode) : IteratorBase(pNode){}
DLLIterator(const base& other) : IteratorBase(other.pNode){}
self& operator=(const self& other){ pNode = other.pNode; return *this; }
virtual self operator ++ (int){ self temp(this->pNode); incr(); return temp; }
virtual self operator -- (int){ self temp(this->pNode); decr(); return temp; }
virtual self& operator ++ (){ incr(); return *this; }
virtual self& operator -- (){ decr(); return *this; }
//virtual E& operator*(){ if (pNode) return pNode->element; }
};

// doubly linked list class
Expand All @@ -89,6 +53,10 @@ namespace ds{
protected:
// typedefs
typedef Node node_t;
public:
typedef DLLIterator<E, Node> iterator;
typedef node_t NodeType;
protected:

// new members
//node_t* pTail;
Expand Down
Loading

0 comments on commit 8e00e2a

Please sign in to comment.