diff --git a/YASI_12/YASI_12.vcxproj b/YASI_12/YASI_12.vcxproj
index cf38240..b99fcc7 100644
--- a/YASI_12/YASI_12.vcxproj
+++ b/YASI_12/YASI_12.vcxproj
@@ -46,6 +46,7 @@
true
"$(SolutionDir)\gtest-1.7.0\include"
MultiThreadedDebug
+ true
true
diff --git a/YASI_12/common.h b/YASI_12/common.h
index 02a6a7a..5f60b40 100644
--- a/YASI_12/common.h
+++ b/YASI_12/common.h
@@ -52,4 +52,14 @@ namespace yasi{
#define IS_POW_OF_TWO(x) ( ((x) >= 1) && ( ((x) & ((x)-1)) == 0) )
+// various types
+ typedef unsigned int uint;
+ typedef unsigned char byte;
+
+// Windows specific
+#if _WIN32
+ // disable "inherits via dominance" warning for virtual inheritance diamond cases
+ #pragma warning( disable : 4250)
+#endif
+
} // namespace yasi
\ No newline at end of file
diff --git a/YASI_12/ds.HopScotchHashTable.h b/YASI_12/ds.HopScotchHashTable.h
index faf3f1b..1553e8b 100644
--- a/YASI_12/ds.HopScotchHashTable.h
+++ b/YASI_12/ds.HopScotchHashTable.h
@@ -146,7 +146,7 @@ protected:
}
- inline void setBitmap(const int bucket, const unsigned int position, const unsigned int bit) const{
+ inline void setBitmap(const unsigned int bucket, const unsigned int position, const unsigned int bit) const{
if (bucket >= 0 && bucket < _size &&
position >= 0 && position < H &&
bit <= 1){
@@ -236,7 +236,7 @@ protected:
hashCurIsAtLeftOfEmptySlot = diffHashCurToEmptySlot > 0;
hashCurIsAtRightOfFirstBucket = hashCur - firstBucket > 0;
- emptySlotInNeighborhoodOfHashCur = diffHashCurToEmptySlot < H;
+ emptySlotInNeighborhoodOfHashCur = diffHashCurToEmptySlot < (int) H;
}
else{
// firstBucket >= emptySlot
@@ -248,7 +248,7 @@ protected:
if (hashCur > firstBucket){
hashCurIsAtRightOfFirstBucket = true;
hashCurIsAtLeftOfEmptySlot = true;
- emptySlotInNeighborhoodOfHashCur = diffHashCurToEmptySlot < H;
+ emptySlotInNeighborhoodOfHashCur = diffHashCurToEmptySlot < (int) H;
}
else{
if (hashCur == firstBucket) return NULL;
@@ -257,7 +257,7 @@ protected:
if (hashCur < emptySlot){
hashCurIsAtRightOfFirstBucket = true;
hashCurIsAtLeftOfEmptySlot = true;
- emptySlotInNeighborhoodOfHashCur = diffHashCurToEmptySlot < H;
+ emptySlotInNeighborhoodOfHashCur = diffHashCurToEmptySlot < (int) H;
}
else{
// hashCur >= emptySlot
@@ -278,7 +278,7 @@ protected:
// returns NULL if the pull is unsuccessful
BucketType* pullFromLeft(const int firstBucket, const int emptySlot){
//when to stop
- int remainingSlots = circularDiff(firstBucket, emptySlot);
+ uint remainingSlots = circularDiff(firstBucket, emptySlot);
if (remainingSlots < H){
// the empty slot is within the neighborhood of firstBucket
return &table[emptySlot];
@@ -344,7 +344,7 @@ protected:
}
// found an empty slot
- int positionInBucket = circularDiff(firstBucket, cur);
+ uint positionInBucket = circularDiff(firstBucket, cur);
if ( positionInBucket < H){
// empty slot within the neighborhood of firstBucket
table[cur].key = k;
@@ -395,7 +395,7 @@ protected:
#endif
// keep probing to the right
// the item, if exists, must be in the neighborhood H
- for (int i = 0; i < H; i = nextPosInBucket(bitmap, i)){
+ for (uint i = 0; i < H; i = nextPosInBucket(bitmap, i)){
if (table[firstBucket + i].key == k)
return &table[firstBucket + i];
#if _DEBUG
diff --git a/YASI_12/ds.HopScotchHashTable.test.h b/YASI_12/ds.HopScotchHashTable.test.h
index 765b98a..8645300 100644
--- a/YASI_12/ds.HopScotchHashTable.test.h
+++ b/YASI_12/ds.HopScotchHashTable.test.h
@@ -547,7 +547,7 @@ namespace yasi{
///////// test resizing when a bucket gets more than H items
IntHashTable32 h2(4, 4); // keep the hash func mod 32 so that we can grow and rehash
- for (int i = 0; i < h2.H; i++){
+ for (uint i = 0; i < h2.H; i++){
h2.insert(16 * i + 2, i); // all hashed to 2
}
ASSERT_EQ(16, h2.size());
diff --git a/YASI_12/ds.LinearProbingHashTable.h b/YASI_12/ds.LinearProbingHashTable.h
index 4fe1f48..89ab704 100644
--- a/YASI_12/ds.LinearProbingHashTable.h
+++ b/YASI_12/ds.LinearProbingHashTable.h
@@ -65,7 +65,7 @@ namespace ds{
else
return _size - low + high;
}
- inline unsigned bool circularBetweenInclusive(const int bucket, const int left, const int right) const{
+ inline bool circularBetweenInclusive(const int bucket, const int left, const int right) const{
if (left == right && bucket != left) return false;
if (left < right){
return left <= bucket && bucket <= right;
@@ -208,7 +208,7 @@ namespace ds{
// non-zero key
Pred keyEquals;
unsigned int curFirstBucket = index(k);
- int cur = curFirstBucket;
+ unsigned int cur = curFirstBucket;
const int searchStart = curFirstBucket; // remember our first posti
do{
//Pair* pEntry = table[cur];
diff --git a/YASI_12/ds.LinearProbingHashTable.test.h b/YASI_12/ds.LinearProbingHashTable.test.h
index 6536ce6..7f71621 100644
--- a/YASI_12/ds.LinearProbingHashTable.test.h
+++ b/YASI_12/ds.LinearProbingHashTable.test.h
@@ -157,7 +157,7 @@ namespace yasi{
// check that all items exist
// items are rehashed mod 32
- for (int i = 0; i < h1._size; i++){
+ for (uint i = 0; i < h1._size; i++){
if (!h1.isNull(i)){
int key = h1.key(i);
int value = h1.value(i);
diff --git a/YASI_12/ds.SeparateChainingHashTable.h b/YASI_12/ds.SeparateChainingHashTable.h
index d425ce1..90e36c6 100644
--- a/YASI_12/ds.SeparateChainingHashTable.h
+++ b/YASI_12/ds.SeparateChainingHashTable.h
@@ -93,7 +93,7 @@ namespace ds{
virtual ~SeparateChainingHashTable(){
if (table){
- for (int i = 0; i < _size; i++){
+ for (uint i = 0; i < _size; i++){
// each entry is either NULL or a List*
if (table[i]){
table[i]->clear();
diff --git a/YASI_12/ds.SeparateChainingHashTable.test.h b/YASI_12/ds.SeparateChainingHashTable.test.h
index 9ab1b97..703d006 100644
--- a/YASI_12/ds.SeparateChainingHashTable.test.h
+++ b/YASI_12/ds.SeparateChainingHashTable.test.h
@@ -22,9 +22,9 @@ namespace yasi{
srand((unsigned int)time(NULL));
for (int i = 0; i < 1000; i++){
int n = rand();
- int index = h.index(n);
+ uint index = h.index(n);
ASSERT_LT(index, h.size()) << "index(" << n << ") out of range";
- ASSERT_GE(index, 0) << "index(" << n << ") out of range";
+ ASSERT_GE(index, 0u) << "index(" << n << ") out of range";
}
}
@@ -34,7 +34,7 @@ namespace yasi{
int size = h._size;
ASSERT_EQ(IntHashTable::INIT_LOGSIZE, logSize) << "initial logSize not " << IntHashTable::INIT_LOGSIZE;
ASSERT_EQ(1 << logSize, h.size()) << "table size not 2^" << logSize;
- for (int i = 0; i < h.size(); i++){
+ for (uint i = 0; i < h.size(); i++){
ASSERT_EQ(0, (int)h.table[i]) << "table[i] not NULL for i=" << i;
}
@@ -108,7 +108,7 @@ namespace yasi{
{
SCOPED_TRACE("remove");
// now remove entries but do not trigger shrink()
- int i = 0;
+ uint i = 0;
BucketType pCriticalBucket = NULL;
DoublyLinkedList survivedKeys;
int initPop = h.population();
diff --git a/YASI_12/ds.arraybinarytree.h b/YASI_12/ds.arraybinarytree.h
index 5fb048a..7d8456d 100644
--- a/YASI_12/ds.arraybinarytree.h
+++ b/YASI_12/ds.arraybinarytree.h
@@ -90,7 +90,7 @@ namespace yasi{
virtual void fromArray(const E*, const int) = 0;
virtual int getRootIndex() const = 0;
virtual Node* nodeAt(int) const = 0;
- virtual Node* insertAt(const E& e, int) = 0;
+ virtual Node* insertAt(const E& e, uint) = 0;
};
@@ -109,18 +109,18 @@ namespace yasi{
const int ROOT_INDEX = 1; // for quick parent-child indexing, 1 instead of 0
// the underlying container
- const int INIT_CAPACITY = 2; // initial size of the array
+ const uint INIT_CAPACITY = 2; // initial size of the array
const float LOAD_FACTOR = 2; // how much the array size increases at each resize
// do not initialize _capacity and _size here; let constructors do that
- int _capacity; // current length of the array, not necessarily the same as the capacity of a vector (due to automatic resizing)
- int _size; // the actual size of the tree, always <= _capacity.
+ uint _capacity; // current length of the array, not necessarily the same as the capacity of a vector (due to automatic resizing)
+ uint _size; // the actual size of the tree, always <= _capacity.
// the vector
vector< node_t* > _arr; // the array of pointers to nodes
// returns true if 0 <= index < capacity
- bool isArrIndex(int k) const{
+ bool isArrIndex(uint k) const{
return k >= 0 && k < _capacity;
}
// returns true if the node-ptr at index is not null
@@ -192,7 +192,7 @@ namespace yasi{
// increases the size of the array
// initializes new slots with NULL pointer
void resize(int newSize, node_t* initValue = 0){
- int i = _capacity; // old capacity
+ uint i = _capacity; // old capacity
_arr.resize(newSize, initValue);
_capacity = _arr.capacity() - 1; // new capacity; one less than vector-capacity to possibly stop auto-resize
while (i < _capacity){
@@ -304,8 +304,8 @@ namespace yasi{
*ppDestArr = new E[_size];
E* pDestArr = *ppDestArr;
- int countElems = 0; // how many elements touched
- for (int i = 1; i < _capacity && countElems < _size; i++){ // discard the index 0
+ uint countElems = 0; // how many elements touched
+ for (uint i = 1; i < _capacity && countElems < _size; i++){ // discard the index 0
node_t* pNode = nodeAt(i);
if (pNode != NULL){
pDestArr[countElems] = pNode->element;
@@ -325,7 +325,7 @@ namespace yasi{
}
void clear(){
// delete each pointer contained in the vector
- for (int i = 0; i < _capacity && i < _arr.size(); i++){
+ for (uint i = 0; i < _capacity && i < _arr.size(); i++){
DELETE_SAFE(_arr[i]);
}
@@ -357,7 +357,7 @@ namespace yasi{
// (3) does not check parent/child relationship; the node can be possibly without a parent
// dynamically allocates a new node; increases the tree-size by one
// returns the node-ptr on success, NULL on failure
- node_t* insertAt(const E& e, int index) override{
+ node_t* insertAt(const E& e, uint index) override{
node_t* pNode = NULL;
if (index > 0){
while (index >= _capacity){
@@ -471,7 +471,7 @@ namespace yasi{
string toStringNodeArray(const char* strDelim, const char* strEmptySlot) const{
// cout << endl << "ArrayBinaryTree contents:" << endl;
std::stringstream buffer;
- for (int i = 0; i < _capacity; i++){
+ for (uint i = 0; i < _capacity; i++){
if (_arr[i] == NULL){
// print empty slots
buffer << strEmptySlot;
diff --git a/YASI_12/ds.arraybinarytree.test.h b/YASI_12/ds.arraybinarytree.test.h
index 27c50c0..c573986 100644
--- a/YASI_12/ds.arraybinarytree.test.h
+++ b/YASI_12/ds.arraybinarytree.test.h
@@ -22,7 +22,7 @@ namespace yasi{
ASSERT_EQ(7, n1.element) << "element should be 5";
n1.makeNull();
- ASSERT_EQ(1, n1.isNull()) << "makeNull() and isNull() disagree";
+ ASSERT_EQ(true, n1.isNull()) << "makeNull() and isNull() disagree";
}
void indexing(){
const int N = 7;
@@ -77,9 +77,9 @@ namespace yasi{
ArrayBinaryTree bt;
ASSERT_EQ(1, bt.ROOT_INDEX) << "Index of root is not 1";
ASSERT_LE(bt.INIT_CAPACITY, bt._arr.capacity()) << "Initial _capacity must be <= containers capacity";
- ASSERT_LE(2, bt._arr.capacity()) << "Initial capacity must be >= 2";
+ ASSERT_LE((uint)2, bt._arr.capacity()) << "Initial capacity must be >= 2";
ASSERT_EQ(0, bt.size()) << "Initial size is not zero";
- for (int i = 0; i < bt._capacity; i++){
+ for (uint i = 0; i < bt._capacity; i++){
ASSERT_EQ(0, bt._arr[i]) << "Pointer at index " << i << " is not initialized to NULL";
}
@@ -103,12 +103,12 @@ namespace yasi{
void fromArr(){
int srcArr[] = { 10, 20, 30, 40, 50, 60 };
- int n = ARR_LENGTH(srcArr);
+ uint n = ARR_LENGTH(srcArr);
ArrayBinaryTree bt(srcArr, n);
ASSERT_EQ(n, bt.size()) << "size of tree is not " << n;
// check node-ptrs stored in internal container
int i = 0;
- for (int i = 0; i < bt._capacity; i++){
+ for (uint i = 0; i < bt._capacity; i++){
if (i >= 1 && i <= n){
// valid node-ptrs
ASSERT_NE(0, (int)bt._arr[i]) << "Pointer NULL at index " << i;
diff --git a/YASI_12/ds.binaryheap.h b/YASI_12/ds.binaryheap.h
index 1453180..33eccbe 100644
--- a/YASI_12/ds.binaryheap.h
+++ b/YASI_12/ds.binaryheap.h
@@ -245,7 +245,6 @@ public:
// returns the top element
const E& top()const override {
- E e;
if (size() > 0){
return bt.root()->element;
}
diff --git a/YASI_12/ds.doublylinkedlist.h b/YASI_12/ds.doublylinkedlist.h
index baccdd6..e657c54 100644
--- a/YASI_12/ds.doublylinkedlist.h
+++ b/YASI_12/ds.doublylinkedlist.h
@@ -79,6 +79,9 @@ namespace ds{
public:
typedef DLLIterator iterator;
typedef node_t NodeType;
+
+ // parent methods/variables
+
/////// constructor/destructor ///////////
DoublyLinkedList(){
// make a unit circle: horizon--horizon--horizon
diff --git a/YASI_12/ds.doublylinkedlist.test.h b/YASI_12/ds.doublylinkedlist.test.h
index c5737d9..3d2d28a 100644
--- a/YASI_12/ds.doublylinkedlist.test.h
+++ b/YASI_12/ds.doublylinkedlist.test.h
@@ -19,7 +19,6 @@ namespace yasi{
template
void checkListElements(DoublyLinkedList >* pList, const E* srcArr, const int n){
E* pElems = new E[n];
- int numElems;
DoublyLinkedList >& list = *pList;
list.elements(&pElems);
ASSERT_EQ(true, arrcmp(srcArr, pElems, n)) << "arrays are not the same" << endl
diff --git a/YASI_12/ds.hashtablebase.h b/YASI_12/ds.hashtablebase.h
index b6a77df..973f7d4 100644
--- a/YASI_12/ds.hashtablebase.h
+++ b/YASI_12/ds.hashtablebase.h
@@ -1,8 +1,8 @@
#pragma once
#include "common.h"
#include "ds.kvpair.h"
-#include "ds.doublylinkedlist.h"
-#include "ds.iterator.h"
+//#include "ds.doublylinkedlist.h"
+//#include "ds.iterator.h"
using namespace std;
namespace yasi{
@@ -16,7 +16,7 @@ protected:
RESIZE_GROW = 0,
RESIZE_SHRINK
};
- virtual void resize(const int growOrShrink, const unsigned int logFactor) = 0;
+ virtual void resize(const int growOrShrink, const unsigned int logFactor = 1) = 0;
void grow() { resize(RESIZE_GROW, 1); } // doubles the capacity
void shrink() { resize(RESIZE_SHRINK, 1); } // halves the capacity
public:
@@ -154,7 +154,7 @@ protected:
// grows/shrinks by specified logFactor
// that is, newSize is either oldSize << logFactor (grow)
// or oldSize >> logFactor (shrink)
- virtual void resize(int growOrShrink, unsigned int logFactor = 1) {
+ virtual void resize(const int growOrShrink, const unsigned int logFactor = 1) {
unsigned int oldLogSize = _logSize;
unsigned int oldSize = _size;
unsigned int oldPopulation = _population;
@@ -202,7 +202,6 @@ protected:
}
public:
// the type of the entries in the hash table
- HashTableBase():HashTableBase(INIT_LOGSIZE){}
HashTableBase(unsigned int logSize = INIT_LOGSIZE) : _logSize(logSize), _size(1 << logSize), _population(0), DENSITY_MAX(0.75), DENSITY_MIN(0.25){
assert(_logSize > 0);
// table = new BucketType[_size];
@@ -220,7 +219,7 @@ public:
string toString() const{
stringstream buf;
- for (int i = 0; i < _size; i++){
+ for (uint i = 0; i < _size; i++){
buf << "[" << i << "] ";
if (!isBucketEmpty(i)) buf << table[i];
buf << endl;
diff --git a/YASI_12/ds.iterator.h b/YASI_12/ds.iterator.h
index f5c3f8d..02347ce 100644
--- a/YASI_12/ds.iterator.h
+++ b/YASI_12/ds.iterator.h
@@ -130,7 +130,23 @@ namespace yasi{
NodeIteratorBase(Node* pNode) : IteratorBase(pNode){}
NodeIteratorBase(const self& other) : IteratorBase(other.pNode){}
// operators
- virtual E& operator* () const override { E e; if (pNode) return pNode->element; else return e; }
+ // if the pNode is NULL, behavior is undefined
+ virtual E& operator* () const override {
+ E e;
+ if (pNode)
+ return pNode->element;
+ else
+ // undefined behavior
+ // in MSVC, disable warning "returning address of local variable or temporary"
+#ifdef _MSC_VER
+# pragma warning( push )
+# pragma warning( disable:4172)
+#endif
+ return e;
+#ifdef _MSC_VER
+# pragma warning( pop )
+#endif
+ }
self& operator=(const self& other){ pNode = other.pNode; return *this; }
};
diff --git a/YASI_12/ds.singlylinkedlist.h b/YASI_12/ds.singlylinkedlist.h
index b6de2d3..cc3f48b 100644
--- a/YASI_12/ds.singlylinkedlist.h
+++ b/YASI_12/ds.singlylinkedlist.h
@@ -216,7 +216,7 @@ public:
return _size;
}
inline bool empty() const override{
- return _size == 0 (pHorizon == pHorizon->next() );
+ return _size == 0 && (pHorizon == pHorizon->next() );
}
virtual void push(const E& e) override{
this->addFront(e);
diff --git a/YASI_12/ds.singlylinkedlist.test.h b/YASI_12/ds.singlylinkedlist.test.h
index 9981790..a66f8c9 100644
--- a/YASI_12/ds.singlylinkedlist.test.h
+++ b/YASI_12/ds.singlylinkedlist.test.h
@@ -21,7 +21,6 @@ namespace yasi{
template
void checkListElements(SinglyLinkedList >* pList, const E* srcArr, const int n){
E* pElems = new int[n];
- int numElems;
SinglyLinkedList >& list = *pList;
list.elements(&pElems);
ASSERT_EQ(true, arrcmp(srcArr, pElems, n)) << "arrays are not the same" << endl
@@ -52,9 +51,8 @@ namespace yasi{
}
void clear(){
- int e, temp;
- bool ok;
- node_t *n1, *n2, *n3, *n4, *n5;
+ int temp;
+ node_t *n1;
IntList list;
ASSERT_EQ(0, list.size()) << "size should be zero";
ASSERT_EQ(0, (int)list.head()) << "head should be NULL";
diff --git a/YASI_12/utils.h b/YASI_12/utils.h
index 726bfc1..04a307c 100644
--- a/YASI_12/utils.h
+++ b/YASI_12/utils.h
@@ -56,7 +56,7 @@ string strPurge(const string str, const char* removeChars){
int numChars = strlen(removeChars);
if (numChars == 0) return str;
- for (int i = 0; i < str.length(); i++){
+ for (uint i = 0; i < str.length(); i++){
bool good = true;
// try every bad char
for (int j = 0; j < numChars; j++){
diff --git a/gtest-1.7.0/msvc/gtest/gtest.tlog/CL.read.1.tlog b/gtest-1.7.0/msvc/gtest/gtest.tlog/CL.read.1.tlog
index 805ee4b..d3d6794 100644
Binary files a/gtest-1.7.0/msvc/gtest/gtest.tlog/CL.read.1.tlog and b/gtest-1.7.0/msvc/gtest/gtest.tlog/CL.read.1.tlog differ
diff --git a/gtest-1.7.0/msvc/gtest/gtest.tlog/cl.command.1.tlog b/gtest-1.7.0/msvc/gtest/gtest.tlog/cl.command.1.tlog
index f0a687c..0c450d0 100644
Binary files a/gtest-1.7.0/msvc/gtest/gtest.tlog/cl.command.1.tlog and b/gtest-1.7.0/msvc/gtest/gtest.tlog/cl.command.1.tlog differ
diff --git a/gtest-1.7.0/msvc/gtest/gtest.tlog/lib.command.1.tlog b/gtest-1.7.0/msvc/gtest/gtest.tlog/lib.command.1.tlog
index 1e2396b..23e35ca 100644
Binary files a/gtest-1.7.0/msvc/gtest/gtest.tlog/lib.command.1.tlog and b/gtest-1.7.0/msvc/gtest/gtest.tlog/lib.command.1.tlog differ
diff --git a/gtest-1.7.0/msvc/gtest/vc120.idb b/gtest-1.7.0/msvc/gtest/vc120.idb
index bc8d9aa..cc61c5c 100644
Binary files a/gtest-1.7.0/msvc/gtest/vc120.idb and b/gtest-1.7.0/msvc/gtest/vc120.idb differ
diff --git a/gtest-1.7.0/msvc/gtestd.lib b/gtest-1.7.0/msvc/gtestd.lib
index 695022a..c303275 100644
Binary files a/gtest-1.7.0/msvc/gtestd.lib and b/gtest-1.7.0/msvc/gtestd.lib differ