You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@concerted.apache.org by at...@apache.org on 2015/10/23 20:52:18 UTC
[1/2] incubator-concerted git commit: Restructure source directory to
a more modular hierarchy. Patch by Anand Rathi. Reviewed by Atri Sharma
Repository: incubator-concerted
Updated Branches:
refs/heads/master 5adf3c4e5 -> fa6ba9867
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/src/ConcSegHashTable.h
----------------------------------------------------------------------
diff --git a/src/ConcSegHashTable.h b/src/ConcSegHashTable.h
deleted file mode 100644
index 764e323..0000000
--- a/src/ConcSegHashTable.h
+++ /dev/null
@@ -1,221 +0,0 @@
-#include "QueueLock.h"
-
-template<class data_val_type> class ConcSegHashTable
-{
- data_val_type **hash_tables;
- QueueLock *read_lock_queues;
- QueueLock *write_lock_queues;
- int number_of_segments;
- int number_of_buckets;
- int last_insert_segment;
-public:
- ConcSegHashTable(int m,int n)
- {
- int i;
- int j;
-
- i = 0;
- j = 0;
- number_of_segments = n;
- number_of_buckets = m;
- last_insert_segment = -1;
- hash_tables = new data_val_type*[n];
- for(i = 0;i < n;i++)
- {
- *(hash_tables + i) = new data_val_type[m];
- for(j = 0;j < m;j++)
- {
- *(*(hash_tables + i) + j) = 0;
- }
-
- }
-
- read_lock_queues = new QueueLock[m * n];
- write_lock_queues = new QueueLock[m * n];
- read_lock_queues->SetTimeOutPeriod(3.0);
- write_lock_queues->SetTimeOutPeriod(3.0);
- }
-
- int HashVal(data_val_type val)
- {
-
- return ((val/3) + 1);
- }
-
- int GetReadLock(int seg_index, int pos, char *name1)
- {
- QueueLock *current_write = write_lock_queues + (seg_index + pos);
- QueueLock *current_read = read_lock_queues + (seg_index + pos);
- const volatile int *p_write_lock_flag = current_write->GetPointerToFlag();
-
- if(current_write->CheckLockIsAcquired() == 1)
- {
- while(*(p_write_lock_flag) != 0)
- {
- //Spinning waiting for write lock to release
- }
-
- }
-
- return (current_read->GetLock(name1));
- }
-
- int GetWriteLock(int seg_index, int pos, char *name1)
- {
- QueueLock *current_write = write_lock_queues + (seg_index + pos);
- QueueLock *current_read = read_lock_queues + (seg_index + pos);
- const int *p_read_lock_flag = current_read->GetPointerToFlag();
-
- if(current_read->CheckLockIsAcquired())
- {
- while(*(p_read_lock_flag) != 0)
- {
- //Spinning waiting for read lock to release
- }
-
- }
-
- return (current_write->GetLock(name1));
- }
-
- void UpgradeLock(int seg_index, int pos, char *name1)
- {
- int i;
-
- QueueLock *current_write = write_lock_queues + (seg_index + pos);
-
- current_write->ForceLock(name1); //We need to immediately get a write lock in order to upgrade the lock.
- ReleaseReadLock(name1);
- }
-
- void ReleaseWriteLock(int seg_index, int pos, char *name1)
- {
- QueueLock *current_write = write_lock_queues + (seg_index + pos);
-
- current_write->ReleaseLock(name1);
- cout<<"Write lock released"<<endl;
- }
-
- void ReleaseReadLock(int seg_index, int pos, char *name1)
- {
- QueueLock *current_read = read_lock_queues + (seg_index + pos);
-
- current_read->ReleaseLock(name1);
- }
-
- int SegmentInsert(int seg_index, data_val_type val, int pos, bool ReplaceValue, char *name1)
- {
- int get_write_lock = 0;
- int get_read_lock = 0;
- int check_lock_status = 0;
-
- check_lock_status = (write_lock_queues + (seg_index + pos))->CheckLockIsAcquired();
- if(check_lock_status == 1)
- {
- cout<<"Lock already taken"<<endl;
- }
- else
- {
- get_write_lock = GetWriteLock(seg_index, pos, name1);
- if(get_write_lock == 0)
- {
- cout<<"did not get lock"<<" "<<seg_index<<" "<<pos<<" "<<name1<<endl;
- return (0);
- }
-
- if(*(*(hash_tables + seg_index) + pos) == 0 || ReplaceValue == true)
- {
- *(*(hash_tables + seg_index) + pos) = val;
- ReleaseWriteLock(seg_index, pos, name1);
-
- return (1);
- }
-
- }
-
- return (0);
- }
-
- int InsertElement(data_val_type val, bool ReplaceValue, char *name1)
- {
- int i;
- int k;
- int j;
- int pos = HashVal(val);
-
- j = 0;
-
- if(last_insert_segment == -1)
- {
- k = 0;
- }
- else
- {
- k = last_insert_segment;
- }
-
- for(i = k;i < number_of_segments;i++)
- {
- if(SegmentInsert(i, val, pos, false, name1) == 1)
- {
- cout<<"value inserted at"<<" "<<i<<" "<<pos<<endl;
- last_insert_segment = i;
- return 1;
- }
-
- }
-
- for(i = 0;i < k;i++)
- {
- if(SegmentInsert(i, val, pos, false, name1) == 1)
- {
- cout<<"value inserted at"<<" "<<i<<" "<<pos<<endl;
- last_insert_segment = i;
- return 1;
- }
-
- }
-
- for(i = k;i < number_of_segments;i++)
- {
- for(j = pos;j < number_of_buckets;j++)
- {
- if(SegmentInsert(i, val, j, false, name1) == 1)
- {
- cout<<"value inserted open addressing"<<" "<<i<<" "<<j<<endl;
- return (1);
- }
-
- }
-
- }
-
- return (0);
- }
-
- void PrintValues()
- {
- int i;
- int j;
-
- i = 0;
- j = 0;
-
- for(i = 0;i < number_of_segments;i++)
- {
- for(j = 0;j < number_of_buckets;j++)
- {
- cout<<i<<" "<<j<<" "<<*(*(hash_tables + i) + j)<<endl;
- }
-
- }
-
- }
- ~ConcSegHashTable()
- {
- delete hash_tables[number_of_segments];
- delete[] read_lock_queues;
- delete[] write_lock_queues;
- }
-
-};
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/src/QueueLock.h
----------------------------------------------------------------------
diff --git a/src/QueueLock.h b/src/QueueLock.h
deleted file mode 100644
index e7549b8..0000000
--- a/src/QueueLock.h
+++ /dev/null
@@ -1,122 +0,0 @@
-#include "ConcQueue.h"
-#include <ctime>
-
-#define BILLION 1E9
-
-class QueueLock
-{
- ConcQueue<int> lock_queue;
- int lock_taken;
- int number_of_elements;
- float timeout_period;
-public:
- QueueLock():lock_taken(0),number_of_elements(0),timeout_period(3.0)
- {
- }
-
- int GetLock(char *name1)
- {
- struct timespec requestStart, requestEnd;
- if(lock_taken != 0)
- {
- const QueueElement<int> *p_add = lock_queue.AddElement(0);
- ++number_of_elements;
- const volatile int *p_spin = p_add->GetPointerToData();
-
- clock_gettime(CLOCK_REALTIME, &requestStart);
-
- while(*(p_spin) != 1)
- {
- //Spinning waiting for lock
- clock_gettime(CLOCK_REALTIME, &requestEnd);
-
- double accum = ( requestEnd.tv_sec - requestStart.tv_sec )
- + ( requestEnd.tv_nsec - requestStart.tv_nsec )
- / BILLION;
-
- if(accum >= timeout_period)
- {
- break;
- return (0);
- }
-
- }
-
- }
-
- lock_taken = 1;
-
- return (1);
- }
-
- void ReleaseLock(char *name1)
- {
- QueueElement<int> *p_release = lock_queue.GetElement();
-
- if(p_release == NULL)
- {
- lock_taken = 0;
- }
- else
- {
- --number_of_elements;
- p_release->SetData(1);
- }
-
- }
-
- int ForceLock(char *name1) //Use with EXTREME caution.
- {
- const QueueElement<int> *p_add = lock_queue.AddElementInFront(0);
- const int *p_spin = p_add->GetPointerToData();
- struct timespec requestStart, requestEnd;
-
- if(lock_taken != 0)
- {
- clock_gettime(CLOCK_REALTIME, &requestStart);
-
- while(*(p_spin) != 1)
- {
- //Spinning waiting for lock
- clock_gettime(CLOCK_REALTIME, &requestEnd);
-
- double accum = ( requestEnd.tv_sec - requestStart.tv_sec )
- + ( requestEnd.tv_nsec - requestStart.tv_nsec )
- / BILLION;
-
- if(accum >= timeout_period)
- {
- break;
- return (0);
- }
-
- }
-
- }
-
- lock_taken = 1;
-
- return (1);
- }
-
-
- int CheckLockIsAcquired()
- {
-
- return (lock_taken);
- }
-
- const int* GetPointerToFlag() const
- {
-
- return (&lock_taken);
- }
-
- void SetTimeOutPeriod(float timeout_period_val)
- {
- timeout_period = timeout_period_val;
- }
-
-};
-
-
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/src/QueueLock2.h
----------------------------------------------------------------------
diff --git a/src/QueueLock2.h b/src/QueueLock2.h
deleted file mode 100644
index e4ada9e..0000000
--- a/src/QueueLock2.h
+++ /dev/null
@@ -1,122 +0,0 @@
-#include "ConcQueue.h"
-#include <ctime>
-
-#define BILLION 1E9
-
-class QueueLock
-{
- ConcQueue<int> lock_queue;
- int lock_taken;
- int number_of_elements;
- float timeout_period;
-public:
- QueueLock():lock_taken(0),number_of_elements(0),timeout_period(3.0)
- {
- }
-
- int GetLock()
- {
- struct timespec requestStart, requestEnd;
- if(lock_taken != 0)
- {
- const QueueElement<int> *p_add = lock_queue.AddElement(0);
- ++number_of_elements;
- const volatile int *p_spin = p_add->GetPointerToData();
-
- clock_gettime(CLOCK_REALTIME, &requestStart);
-
- while(*(p_spin) != 1)
- {
- //Spinning waiting for lock
- clock_gettime(CLOCK_REALTIME, &requestEnd);
-
- double accum = ( requestEnd.tv_sec - requestStart.tv_sec )
- + ( requestEnd.tv_nsec - requestStart.tv_nsec )
- / BILLION;
-
- if(accum >= timeout_period)
- {
- break;
- return (0);
- }
-
- }
-
- }
-
- lock_taken = 1;
-
- return (1);
- }
-
- void ReleaseLock()
- {
- QueueElement<int> *p_release = lock_queue.GetElement();
-
- if(p_release == NULL)
- {
- lock_taken = 0;
- }
- else
- {
- --number_of_elements;
- p_release->SetData(1);
- }
-
- }
-
- int ForceLock() //Use with EXTREME caution.
- {
- const QueueElement<int> *p_add = lock_queue.AddElementInFront(0);
- const int *p_spin = p_add->GetPointerToData();
- struct timespec requestStart, requestEnd;
-
- if(lock_taken != 0)
- {
- clock_gettime(CLOCK_REALTIME, &requestStart);
-
- while(*(p_spin) != 1)
- {
- //Spinning waiting for lock
- clock_gettime(CLOCK_REALTIME, &requestEnd);
-
- double accum = ( requestEnd.tv_sec - requestStart.tv_sec )
- + ( requestEnd.tv_nsec - requestStart.tv_nsec )
- / BILLION;
-
- if(accum >= timeout_period)
- {
- break;
- return (0);
- }
-
- }
-
- }
-
- lock_taken = 1;
-
- return (1);
- }
-
-
- int CheckLockIsAcquired()
- {
-
- return (lock_taken);
- }
-
- const int* GetPointerToFlag() const
- {
-
- return (&lock_taken);
- }
-
- void SetTimeOutPeriod(float timeout_period_val)
- {
- timeout_period = timeout_period_val;
- }
-
-};
-
-
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/src/TransactionManager.h
----------------------------------------------------------------------
diff --git a/src/TransactionManager.h b/src/TransactionManager.h
deleted file mode 100644
index cb7c1ff..0000000
--- a/src/TransactionManager.h
+++ /dev/null
@@ -1,229 +0,0 @@
-#include <iostream>
-#include "QueueLock2.h"
-#include "ConcDef.h"
-using namespace std;
-
-class TransactionManager
-{
- static int active_transaction_number;
- int current_transaction_number;
- static int counter;
- int lock_counter;
- int memory_counter;
- int commit_val_counter;
- static int active_transactions[10];
- int delete_val;
- ConcertedDef* current_val[10];
- ConcertedDef* copy_val[10];
- void *mem_allocated_val_array[10];
- QueueLock *lock_val_array[10];
-public:
- TransactionManager()
- {
- int i = 0;
-
- for(i = 0;i < 10;i++)
- {
- current_val[i] = NULL;
- copy_val[i] = NULL;
- active_transactions[i] = 0;
- lock_val_array[i] = NULL;
- mem_allocated_val_array[i] = NULL;
- }
-
- if (counter == 10)
- {
- cout<<"A new transaction number cannot be inserted due to lack of space"<<endl;
- throw -1;
- }
-
- current_transaction_number = ++active_transaction_number;
- active_transactions[counter] = active_transaction_number;
- ++counter;
-
- lock_counter = 0;
- memory_counter = 0;
- commit_val_counter = 0;
- delete_val = 1;
- }
-
- int add_transaction()
- {
-
- if (counter == 10)
- {
- cout<<"A new transaction number cannot be inserted due to lack of space"<<endl;
- return -1;
- }
-
- ++active_transaction_number;
- active_transactions[counter] = active_transaction_number;
- ++counter;
-
- return active_transaction_number;
- }
-
- void delete_lock(QueueLock *val)
- {
- int i = 0;
- int j = 0;
-
- for(i = 0;i < lock_counter;i++)
- {
- if (lock_val_array[i] == val)
- {
- lock_val_array[i] = NULL;
- for (j = i;j < lock_counter;j++)
- {
- lock_val_array[j] = lock_val_array[j + 1];
- }
-
- --lock_counter;
- break;
- }
-
- }
-
- }
-
- int add_mem_location(ConcertedDef *mem)
- {
- if (memory_counter == 10)
- {
- cout<<"new memory location val cannot be added due to lack of element in array"<<endl;
- throw -1;
- }
-
- mem_allocated_val_array[memory_counter] = mem;
- ++memory_counter;
-
- return 1;
- }
-
- void delete_mem_location(ConcertedDef *val)
- {
- int i = 0;
- int j = 0;
-
- for (i = 0; i < memory_counter;i++)
- {
- if (mem_allocated_val_array[i] != NULL)
- {
- if (mem_allocated_val_array[i] == val)
- {
- mem_allocated_val_array[i] = NULL;
- for (j = i;j < memory_counter;j++)
- {
- mem_allocated_val_array[j] = mem_allocated_val_array[j + 1];
- }
-
- --memory_counter;
- break;
- }
-
- }
-
- }
-
- }
-
- void delete_transaction(int val)
- {
- int i = 0;
- int j = 0;
-
- for (i = 0;i < 10;i++)
- {
- if (active_transactions[i] == val)
- {
- active_transactions[i] = 0;
- for (j = i;j < counter;j++)
- {
- active_transactions[j] = active_transactions[j + 1];
- }
-
- --counter;
- }
-
- }
-
- }
-
- void add_commit_val(ConcertedDef *val, ConcertedDef *copy_val1)
- {
-
- if (commit_val_counter == 10)
- {
- cout<<"commit val cannot be added due to lack of element in array"<<endl;
- throw -1;
- }
-
- current_val[commit_val_counter] = val;
- copy_val[commit_val_counter] = copy_val1;
- ++commit_val_counter;
- }
-
- void add_lock(QueueLock *val)
- {
-
- if (lock_counter == 10)
- {
- cout<<"lock cannot be added due to lack of element in array"<<endl;
- throw -1;
- }
-
- lock_val_array[lock_counter] = val;
- ++lock_counter;
- }
-
- void commit_transaction()
- {
- int i = 0;
-
- delete_val = 0;
- for (i = 0;i < commit_val_counter;i++)
- {
- (current_val[i])->copy_pointer_val(copy_val[i]);
- }
-
- cout<<"commit"<<endl;
-
- }
-
- ~TransactionManager()
- {
- int i = 0;
-
- if (delete_val == 1)
- {
- cout<<"Rollback"<<endl;
- for (i = 0;i < lock_counter;i++)
- {
- if (lock_val_array[i] != NULL && (lock_val_array[i])->CheckLockIsAcquired())
- {
- lock_val_array[i]->ReleaseLock();
- }
-
- }
-
- i = 0;
-
- for (i = 0;i < memory_counter;i++)
- {
- if (mem_allocated_val_array[i] != NULL)
- {
- free(mem_allocated_val_array[i]);
- }
-
- }
-
- delete_transaction(current_transaction_number);
-
- }
-
- }
-};
-
-int TransactionManager::counter = 0;
-int TransactionManager::active_transaction_number = 0;
-int TransactionManager::active_transactions[10] = {0,0,0,0,0,0,0,0,0,0};
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/test/ConcDCTConcurrencyTest.cpp
----------------------------------------------------------------------
diff --git a/test/ConcDCTConcurrencyTest.cpp b/test/ConcDCTConcurrencyTest.cpp
new file mode 100644
index 0000000..ed775bb
--- /dev/null
+++ b/test/ConcDCTConcurrencyTest.cpp
@@ -0,0 +1,72 @@
+#include "../ConcDCT.h"
+
+ void *thread_lock_test1(void *arg1)
+ {
+ dct_tree *tree_val = (dct_tree*)arg1;
+ int arr_val[3];
+
+ arr_val[0] = 1;
+ arr_val[1] = 2;
+ arr_val[2] = 3;
+
+ insert_val(arr_val, tree_val);
+ }
+
+ void *thread_lock_test2(void *arg1)
+ {
+ dct_tree *tree_val = (dct_tree*)arg1;
+ int arr_val[3];
+
+ arr_val[0] = 4;
+ arr_val[1] = 5;
+ arr_val[2] = 6;
+
+ insert_val(arr_val, tree_val);
+ }
+
+ void *thread_lock_test3(void *arg1)
+ {
+ dct_tree *tree_val = (dct_tree*)arg1;
+ int arr_val[3];
+
+ arr_val[0] = 1;
+ arr_val[1] = 2;
+ arr_val[2] = 3;
+
+ insert_val(arr_val, tree_val);
+ }
+
+ void *thread_lock_test4(void *arg1)
+ {
+ dct_tree *tree_val = (dct_tree*)arg1;
+ int arr_val[3];
+
+ arr_val[0] = 4;
+ arr_val[1] = 5;
+ arr_val[2] = 6;
+
+ search_val(arr_val, tree_val);
+ }
+
+ int main()
+ {
+ dct_tree *tree_val = NULL;
+ pthread_t tid1;
+ pthread_t tid2;
+ pthread_t tid3;
+ pthread_t tid4;
+
+ tree_val = new dct_tree(3);
+
+ pthread_create(&tid1,NULL,thread_lock_test1,(void*)tree_val);
+ pthread_create(&tid2,NULL,thread_lock_test2,(void*)tree_val);
+ pthread_create(&tid3,NULL,thread_lock_test3,(void*)tree_val);
+ pthread_create(&tid4,NULL,thread_lock_test4,(void*)tree_val);
+
+ pthread_join(tid1,NULL);
+ pthread_join(tid2,NULL);
+ pthread_join(tid3,NULL);
+ pthread_join(tid4,NULL);
+ }
+
+
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/test/ConcDCTFileReader.cpp
----------------------------------------------------------------------
diff --git a/test/ConcDCTFileReader.cpp b/test/ConcDCTFileReader.cpp
new file mode 100644
index 0000000..33ac373
--- /dev/null
+++ b/test/ConcDCTFileReader.cpp
@@ -0,0 +1,53 @@
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <string>
+#include "../include/ConcDCT.h"
+
+using namespace std;
+
+std::string line;
+std::ifstream infile("sat.trn");
+
+int main()
+{
+int count;
+int arr_val[3];
+dct_tree *tree_val = NULL;
+TransactionManager t1;
+
+tree_val = build_dcttree(3);
+count = 0;
+while (std::getline(infile, line)) // this does the checking!
+{
+ std::istringstream iss(line);
+ char c;
+
+ int value;
+ while (iss >> value)
+ {
+ if (count == 3)
+ {
+ insert_val(arr_val, tree_val, t1);
+ count = 0;
+ cout<<"record"<<endl;
+ }
+
+ arr_val[count] = value;
+ ++count;
+ }
+}
+
+arr_val[0] = 91;
+arr_val[1] = 100;
+arr_val[2] = 81;
+
+if ((search_val(arr_val, tree_val)) != NULL)
+ {
+ cout<<"All values found"<<endl;
+ }
+ else
+ {
+ cout<<"All values not found"<<endl;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/test/ConcDCTFileReader.cpp~
----------------------------------------------------------------------
diff --git a/test/ConcDCTFileReader.cpp~ b/test/ConcDCTFileReader.cpp~
new file mode 100644
index 0000000..630c35e
--- /dev/null
+++ b/test/ConcDCTFileReader.cpp~
@@ -0,0 +1,53 @@
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <string>
+#include "../ConcDCT.h"
+
+using namespace std;
+
+std::string line;
+std::ifstream infile("sat.trn");
+
+int main()
+{
+int count;
+int arr_val[3];
+dct_tree *tree_val = NULL;
+TransactionManager t1;
+
+tree_val = build_dcttree(3);
+count = 0;
+while (std::getline(infile, line)) // this does the checking!
+{
+ std::istringstream iss(line);
+ char c;
+
+ int value;
+ while (iss >> value)
+ {
+ if (count == 3)
+ {
+ insert_val(arr_val, tree_val, t1);
+ count = 0;
+ cout<<"record"<<endl;
+ }
+
+ arr_val[count] = value;
+ ++count;
+ }
+}
+
+arr_val[0] = 91;
+arr_val[1] = 100;
+arr_val[2] = 81;
+
+if ((search_val(arr_val, tree_val)) != NULL)
+ {
+ cout<<"All values found"<<endl;
+ }
+ else
+ {
+ cout<<"All values not found"<<endl;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/test/ConcDCTTest.cpp
----------------------------------------------------------------------
diff --git a/test/ConcDCTTest.cpp b/test/ConcDCTTest.cpp
new file mode 100644
index 0000000..d17b277
--- /dev/null
+++ b/test/ConcDCTTest.cpp
@@ -0,0 +1,62 @@
+#include "../include/ConcDCT.h"
+ int main()
+ {
+ int att_array[3];
+ int i = 0;
+ TransactionManager transact_val1;
+ dct_tree *tree_val = NULL;
+ dct_tree *tree_val2 = NULL;
+ dct_tree *tree_val3 = NULL;
+ dct_node *temp = NULL;
+ tree_val = build_dcttree(3);
+ tree_val3 = build_dcttree(3);
+ att_array[0] = 1;
+ att_array[1] = 2;
+ att_array[2] = 3;
+ try
+ {
+ insert_val(att_array, tree_val, transact_val1);
+ insert_val(att_array, tree_val3, transact_val1);
+ //throw -1;
+ transact_val1.commit_transaction();
+ tree_val2 = copy_val((tree_val->getdummy()), (tree_val->getnumber_of_nodes()));
+ }catch (int e)
+ {
+ cout<<"exception caught"<<" "<<e<<endl;
+ return 1;
+ }
+
+ //att_array[2] = 3;
+ if (search_val(att_array, tree_val))
+ {
+ cout<<"All values found"<<endl;
+ }
+ else
+ {
+ cout<<"All values not found"<<endl;
+ }
+
+ temp = search_val(att_array, tree_val2);
+ if (temp != NULL)
+ {
+ cout<<" All values found copy tree"<<endl;
+ }
+ else
+ {
+ cout<<"All values not found copy tree"<<endl;
+ }
+
+ if (search_val(att_array, tree_val3))
+ {
+ cout<<"All values found3"<<endl;
+ }
+ else
+ {
+ cout<<"All values not found3"<<endl;
+ }
+
+ delete tree_val;
+ delete tree_val2;
+ delete tree_val3;
+ delete temp;
+ }
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/test/ConcDCTTest.cpp~
----------------------------------------------------------------------
diff --git a/test/ConcDCTTest.cpp~ b/test/ConcDCTTest.cpp~
new file mode 100644
index 0000000..303c166
--- /dev/null
+++ b/test/ConcDCTTest.cpp~
@@ -0,0 +1,62 @@
+#include "../ConcDCT.h"
+ int main()
+ {
+ int att_array[3];
+ int i = 0;
+ TransactionManager transact_val1;
+ dct_tree *tree_val = NULL;
+ dct_tree *tree_val2 = NULL;
+ dct_tree *tree_val3 = NULL;
+ dct_node *temp = NULL;
+ tree_val = build_dcttree(3);
+ tree_val3 = build_dcttree(3);
+ att_array[0] = 1;
+ att_array[1] = 2;
+ att_array[2] = 3;
+ try
+ {
+ insert_val(att_array, tree_val, transact_val1);
+ insert_val(att_array, tree_val3, transact_val1);
+ //throw -1;
+ transact_val1.commit_transaction();
+ tree_val2 = copy_val((tree_val->getdummy()), (tree_val->getnumber_of_nodes()));
+ }catch (int e)
+ {
+ cout<<"exception caught"<<" "<<e<<endl;
+ return 1;
+ }
+
+ //att_array[2] = 3;
+ if (search_val(att_array, tree_val))
+ {
+ cout<<"All values found"<<endl;
+ }
+ else
+ {
+ cout<<"All values not found"<<endl;
+ }
+
+ temp = search_val(att_array, tree_val2);
+ if (temp != NULL)
+ {
+ cout<<" All values found copy tree"<<endl;
+ }
+ else
+ {
+ cout<<"All values not found copy tree"<<endl;
+ }
+
+ if (search_val(att_array, tree_val3))
+ {
+ cout<<"All values found3"<<endl;
+ }
+ else
+ {
+ cout<<"All values not found3"<<endl;
+ }
+
+ delete tree_val;
+ delete tree_val2;
+ delete tree_val3;
+ delete temp;
+ }
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/test/ConcInvertedIndexTest.cpp
----------------------------------------------------------------------
diff --git a/test/ConcInvertedIndexTest.cpp b/test/ConcInvertedIndexTest.cpp
new file mode 100644
index 0000000..35ba9e0
--- /dev/null
+++ b/test/ConcInvertedIndexTest.cpp
@@ -0,0 +1,28 @@
+#include "../include/ConcInvertedIndex.h"
+
+int main()
+ {
+ inv_index<3,0> *index1;
+ int att_values[3];
+ int return_value;
+
+ return_value = 0;
+ index1 = new inv_index<3,0>;
+ att_values[0] = 3;
+ att_values[1] = 4;
+ att_values[2] = 5;
+
+ insert_val(att_values, index1);
+
+ return_value = search_val(&(att_values[0]), index1);
+
+ if (return_value == 1)
+ {
+ cout<<"values found"<<" "<<return_value<<endl;
+ }
+ else
+ {
+ cout<<"values not found"<<" "<<return_value<<endl;
+ }
+
+ }
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/test/ConcInvertedIndexTest.cpp~
----------------------------------------------------------------------
diff --git a/test/ConcInvertedIndexTest.cpp~ b/test/ConcInvertedIndexTest.cpp~
new file mode 100644
index 0000000..424c277
--- /dev/null
+++ b/test/ConcInvertedIndexTest.cpp~
@@ -0,0 +1,28 @@
+#include "../ConcInvertedIndex.h"
+
+int main()
+ {
+ inv_index<3,0> *index1;
+ int att_values[3];
+ int return_value;
+
+ return_value = 0;
+ index1 = new inv_index<3,0>;
+ att_values[0] = 3;
+ att_values[1] = 4;
+ att_values[2] = 5;
+
+ insert_val(att_values, index1);
+
+ return_value = search_val(&(att_values[0]), index1);
+
+ if (return_value == 1)
+ {
+ cout<<"values found"<<" "<<return_value<<endl;
+ }
+ else
+ {
+ cout<<"values not found"<<" "<<return_value<<endl;
+ }
+
+ }
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/test/ConcMATFileReader.cpp
----------------------------------------------------------------------
diff --git a/test/ConcMATFileReader.cpp b/test/ConcMATFileReader.cpp
new file mode 100644
index 0000000..3e924fc
--- /dev/null
+++ b/test/ConcMATFileReader.cpp
@@ -0,0 +1,52 @@
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <string>
+#include "../ConcMAT.h"
+
+using namespace std;
+
+std::string line;
+std::ifstream infile("sat.trn");
+
+int main()
+{
+int count;
+int arr_val[3];
+mat_tree *tree_val = NULL;
+
+tree_val = build_mattree(3);
+count = 0;
+while (std::getline(infile, line)) // this does the checking!
+{
+ std::istringstream iss(line);
+ char c;
+
+ int value;
+ while (iss >> value)
+ {
+ if (count == 3)
+ {
+ insert_val(arr_val, tree_val);
+ count = 0;
+ cout<<"record"<<endl;
+ }
+
+ arr_val[count] = value;
+ ++count;
+ }
+}
+
+arr_val[0] = 91;
+arr_val[1] = 100;
+arr_val[2] = 81;
+
+if ((search_val(arr_val, tree_val)) != NULL)
+ {
+ cout<<"All values found"<<endl;
+ }
+ else
+ {
+ cout<<"All values not found"<<endl;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/test/ConcMATTest.cpp
----------------------------------------------------------------------
diff --git a/test/ConcMATTest.cpp b/test/ConcMATTest.cpp
new file mode 100644
index 0000000..555c033
--- /dev/null
+++ b/test/ConcMATTest.cpp
@@ -0,0 +1,24 @@
+#include "../include/ConcMAT.h"
+
+ int main()
+ {
+ int att_array[3];
+ int i = 0;
+ mat_tree *tree_val = NULL;
+ tree_val = build_mattree(3);
+ att_array[0] = 1;
+ att_array[1] = 2;
+ att_array[2] = 3;
+ insert_val(att_array, tree_val);
+ if (search_val(att_array, tree_val))
+ {
+ cout<<"All values found"<<endl;
+ }
+ else
+ {
+ cout<<"All values not found"<<endl;
+ }
+
+ delete tree_val;
+ }
+
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/test/ConcMATTest.cpp~
----------------------------------------------------------------------
diff --git a/test/ConcMATTest.cpp~ b/test/ConcMATTest.cpp~
new file mode 100644
index 0000000..459cdcc
--- /dev/null
+++ b/test/ConcMATTest.cpp~
@@ -0,0 +1,24 @@
+#include "../ConcMAT.h"
+
+ int main()
+ {
+ int att_array[3];
+ int i = 0;
+ mat_tree *tree_val = NULL;
+ tree_val = build_mattree(3);
+ att_array[0] = 1;
+ att_array[1] = 2;
+ att_array[2] = 3;
+ insert_val(att_array, tree_val);
+ if (search_val(att_array, tree_val))
+ {
+ cout<<"All values found"<<endl;
+ }
+ else
+ {
+ cout<<"All values not found"<<endl;
+ }
+
+ delete tree_val;
+ }
+
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/test/ConcSegHashTableTest.cpp
----------------------------------------------------------------------
diff --git a/test/ConcSegHashTableTest.cpp b/test/ConcSegHashTableTest.cpp
new file mode 100644
index 0000000..92b8ce5
--- /dev/null
+++ b/test/ConcSegHashTableTest.cpp
@@ -0,0 +1,87 @@
+#include "../include/ConcSegHashTable.h"
+
+ConcSegHashTable<int> tab1(10,2);
+void *thread_lock_test(void *arg1)
+{
+ //tab1.GetWriteLock(0,2,(char*)arg1);
+ //tab1.InsertElement(5, false, (char*)arg1);
+ if((tab1.InsertElement(5, false,(char*)arg1)) == 0)
+ {
+ cout<<"Value not inserted"<<" "<<(char*)arg1<<" "<<5<<endl;
+ sleep(1);
+ }
+
+ tab1.InsertElement(6, false,(char*)arg1);
+ //tab1.InsertElement(5, false,(char*)arg1);
+ //tab1.InsertElement(5, false,(char*)arg1);
+ //cout<<"read lock with"<<" "<<(char*)arg1<<endl;
+ //sleep(1);
+ //tab1.ReleaseWriteLock(0,2,(char*)arg1);
+ //cout<<"read lock released by"<<" "<<(char*)arg1<<endl;
+}
+
+void *thread_lock_test2(void *arg1)
+{
+ //tab1.GetWriteLock(0,2, (char*)arg1);
+ //cout<<"write lock with"<<" "<<(char*)arg1<<endl;
+ //tab1.ReleaseWriteLock(0,2, (char*)arg1);
+ //cout<<"write lock released by"<<" "<<(char*)arg1<<endl;
+ if((tab1.InsertElement(5, false, (char*)arg1)) == 0)
+ {
+ cout<<"Value not inserted"<<" "<<(char*)arg1<<" "<<5<<endl;
+ sleep(1);
+ }
+
+ if((tab1.InsertElement(6, false, (char*)arg1)) == 0)
+ {
+ cout<<"Value not inserted"<<" "<<(char*)arg1<<" "<<6<<endl;
+ sleep(1);
+ }
+}
+
+void *thread_lock_test3(void *arg1)
+{
+ /*tab1.GetReadLock(0,2, (char*)arg1);
+ cout<<"read lock with"<<" "<<(char*)arg1<<endl;
+ tab1.ReleaseReadLock(0,2, (char*)arg1);
+ cout<<"read lock released by"<<" "<<(char*)arg1<<endl;*/
+ if((tab1.InsertElement(6, false, (char*)arg1)) == 0)
+ {
+ cout<<"Value not inserted"<<" "<<(char*)arg1<<" "<<6<<endl;
+ }
+
+ //tab1.InsertElement(6, false, (char*)arg1);
+}
+
+void *thread_lock_test4(void *arg1)
+{
+ tab1.InsertElement(6,false,(char*)arg1);
+ tab1.InsertElement(9,false,(char*)arg1);
+}
+
+int main()
+{
+ pthread_t tid1;
+ pthread_t tid2;
+ pthread_t tid3;
+ pthread_t tid4;
+ char name1[] = "thread1";
+ char name2[] = "thread2";
+ char name3[] = "thread3";
+ char name4[] = "thread4";
+
+ pthread_create(&tid1,NULL,thread_lock_test,(void*)name1);
+ pthread_create(&tid2,NULL,thread_lock_test2,(void*)name2);
+ pthread_create(&tid3,NULL,thread_lock_test3,(void*)name3);
+ pthread_create(&tid4,NULL,thread_lock_test4,(void*)name4);
+
+ pthread_join(tid1,NULL);
+ pthread_join(tid2,NULL);
+ pthread_join(tid3,NULL);
+ pthread_join(tid4,NULL);
+
+ tab1.PrintValues();
+
+ //tab1.GetWriteLock(2,3);
+ //tab1.ReleaseWriteLock(2,3);
+}
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/test/ConcSegHashTableTest.cpp~
----------------------------------------------------------------------
diff --git a/test/ConcSegHashTableTest.cpp~ b/test/ConcSegHashTableTest.cpp~
new file mode 100644
index 0000000..6a61a1a
--- /dev/null
+++ b/test/ConcSegHashTableTest.cpp~
@@ -0,0 +1,87 @@
+#include "../ConcSegHashTable.h"
+
+ConcSegHashTable<int> tab1(10,2);
+void *thread_lock_test(void *arg1)
+{
+ //tab1.GetWriteLock(0,2,(char*)arg1);
+ //tab1.InsertElement(5, false, (char*)arg1);
+ if((tab1.InsertElement(5, false,(char*)arg1)) == 0)
+ {
+ cout<<"Value not inserted"<<" "<<(char*)arg1<<" "<<5<<endl;
+ sleep(1);
+ }
+
+ tab1.InsertElement(6, false,(char*)arg1);
+ //tab1.InsertElement(5, false,(char*)arg1);
+ //tab1.InsertElement(5, false,(char*)arg1);
+ //cout<<"read lock with"<<" "<<(char*)arg1<<endl;
+ //sleep(1);
+ //tab1.ReleaseWriteLock(0,2,(char*)arg1);
+ //cout<<"read lock released by"<<" "<<(char*)arg1<<endl;
+}
+
+void *thread_lock_test2(void *arg1)
+{
+ //tab1.GetWriteLock(0,2, (char*)arg1);
+ //cout<<"write lock with"<<" "<<(char*)arg1<<endl;
+ //tab1.ReleaseWriteLock(0,2, (char*)arg1);
+ //cout<<"write lock released by"<<" "<<(char*)arg1<<endl;
+ if((tab1.InsertElement(5, false, (char*)arg1)) == 0)
+ {
+ cout<<"Value not inserted"<<" "<<(char*)arg1<<" "<<5<<endl;
+ sleep(1);
+ }
+
+ if((tab1.InsertElement(6, false, (char*)arg1)) == 0)
+ {
+ cout<<"Value not inserted"<<" "<<(char*)arg1<<" "<<6<<endl;
+ sleep(1);
+ }
+}
+
+void *thread_lock_test3(void *arg1)
+{
+ /*tab1.GetReadLock(0,2, (char*)arg1);
+ cout<<"read lock with"<<" "<<(char*)arg1<<endl;
+ tab1.ReleaseReadLock(0,2, (char*)arg1);
+ cout<<"read lock released by"<<" "<<(char*)arg1<<endl;*/
+ if((tab1.InsertElement(6, false, (char*)arg1)) == 0)
+ {
+ cout<<"Value not inserted"<<" "<<(char*)arg1<<" "<<6<<endl;
+ }
+
+ //tab1.InsertElement(6, false, (char*)arg1);
+}
+
+void *thread_lock_test4(void *arg1)
+{
+ tab1.InsertElement(6,false,(char*)arg1);
+ tab1.InsertElement(9,false,(char*)arg1);
+}
+
+int main()
+{
+ pthread_t tid1;
+ pthread_t tid2;
+ pthread_t tid3;
+ pthread_t tid4;
+ char name1[] = "thread1";
+ char name2[] = "thread2";
+ char name3[] = "thread3";
+ char name4[] = "thread4";
+
+ pthread_create(&tid1,NULL,thread_lock_test,(void*)name1);
+ pthread_create(&tid2,NULL,thread_lock_test2,(void*)name2);
+ pthread_create(&tid3,NULL,thread_lock_test3,(void*)name3);
+ pthread_create(&tid4,NULL,thread_lock_test4,(void*)name4);
+
+ pthread_join(tid1,NULL);
+ pthread_join(tid2,NULL);
+ pthread_join(tid3,NULL);
+ pthread_join(tid4,NULL);
+
+ tab1.PrintValues();
+
+ //tab1.GetWriteLock(2,3);
+ //tab1.ReleaseWriteLock(2,3);
+}
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/test/ConcSkipListTest.cpp
----------------------------------------------------------------------
diff --git a/test/ConcSkipListTest.cpp b/test/ConcSkipListTest.cpp
new file mode 100644
index 0000000..95552ff
--- /dev/null
+++ b/test/ConcSkipListTest.cpp
@@ -0,0 +1,294 @@
+#include "../include/QueueLock.h"
+
+class linked_list
+{
+ int val;
+ linked_list *next;
+public:
+ linked_list()
+ {
+ val = 0;
+ next = NULL;
+ }
+ int getval()
+ {
+ return val;
+ }
+
+ void setval(int a)
+ {
+ val = a;
+ }
+
+ linked_list* getnext()
+ {
+ return next;
+ }
+
+ void setnext(linked_list *val)
+ {
+ next = val;
+ }
+};
+
+class skip_list_master
+{
+ int curr_level;
+ int max_level;
+ float probability_val;
+ linked_list **list_array;
+public:
+ skip_list_master()
+ {
+ curr_level = 0;
+ max_level = 5;
+ list_array = NULL;
+ probability_val = 0.25;
+ }
+
+ void insert_val(int location, int index, linked_list *temp)
+ {
+ linked_list *traverse = NULL;
+ int i = 0;
+
+ if (list_array == NULL)
+ {
+ list_array = (linked_list**)malloc(sizeof(linked_list*));
+ list_array[0] = temp;
+ curr_level = 1;
+
+ cout<<"Inserted condition 1"<<" "<<list_array[0]->getval()<<endl;
+
+ return;
+ }
+
+ i = index;
+ traverse = list_array[location];
+
+ /*while((traverse->getnext()) != NULL && (traverse->getval()) < a && ((traverse->getnext())->getval()) < a)
+ {
+ cout<<"In loop"<<endl;
+ traverse = traverse->getnext();
+ }*/
+
+ while (i > 0)
+ {
+ traverse = traverse->getnext();
+ --i;
+ }
+
+ if ((traverse->getnext()) == NULL)
+ {
+ traverse->setnext(temp);
+ return;
+ }
+ /*else if ((traverse->getval()) >= a)
+ {
+ temp->setnext(traverse);
+ return;
+ }*/
+
+ temp->setnext(traverse->getnext());
+ traverse->setnext(temp);
+
+ }
+
+ void insert_skip(int a)
+ {
+ linked_list **traverse_skip = NULL;
+ linked_list *traverse_list = NULL;
+ linked_list *previous_pointer = NULL;
+ linked_list *temp = NULL;
+ int i = 0;
+ int j = 0;
+ int level = 0;
+ int iteration_value = 0;
+
+ level = level_generate();
+ i = level - 1;
+
+ if (level > max_level)
+ {
+ iteration_value = max_level;
+ }
+ else
+ {
+ iteration_value = level;
+ }
+
+ temp = (linked_list*)malloc(sizeof(linked_list));
+
+ temp->setval(a);
+
+ if (!list_array)
+ {
+ insert_val(a, 0, temp);
+ return;
+ }
+ else
+ {
+ traverse_skip = (linked_list**)malloc(sizeof(linked_list*) * max_level);
+ }
+
+ traverse_list = list_array[level - 1];
+
+ for (i = (level - 1);i >= 0;i--)
+ {
+ previous_pointer = NULL;
+
+ if (j > 0)
+ {
+ while (j > 0)
+ {
+ traverse_list = traverse_list->getnext();
+ --j;
+ }
+ }
+
+ if (traverse_list == NULL)
+ {
+ cout<<"traverse_list is NULL"<<endl;
+ }
+ else
+ {
+ cout<<"traverse_list is not NULL"<<endl;
+ }
+
+ while (traverse_list != NULL && (traverse_list->getval()) < a)
+ {
+ cout<<"In loop 2"<<" "<<(traverse_list->getval())<<endl;
+ ++j;
+ previous_pointer = traverse_list;
+ traverse_list = traverse_list->getnext();
+ }
+
+ traverse_skip[i] = previous_pointer;
+
+ traverse_list = list_array[i];
+ }
+
+ insert_val(0, j, temp);
+ /*for (i = 1;i <= (level - 1);i++)
+ {*/
+
+ }
+
+
+ void print_val()
+ {
+ linked_list *traverse = NULL;
+
+ if (list_array)
+ {
+ traverse = list_array[0];
+ }
+
+ while (traverse != NULL)
+ {
+ cout<<"val is"<<" "<<traverse->getval()<<endl;
+ traverse = traverse->getnext();
+ }
+ }
+
+ int level_generate()
+ {
+ double rand_val = static_cast<double>(rand()) / RAND_MAX;
+ int level = 0;
+
+ while (rand_val > probability_val && level < max_level)
+ {
+ ++level;
+ rand_val = static_cast<double>(rand()) / RAND_MAX;
+ }
+
+ return level;
+ }
+
+ int search_val(int key)
+ {
+ linked_list **traverse_skip = NULL;
+ linked_list *traverse_list = NULL;
+ int i = 0;
+ int j = 0;
+
+ i = curr_level;
+
+ if (!list_array)
+ {
+ return 0;
+ }
+ else
+ {
+ traverse_skip = (linked_list**)malloc(sizeof(linked_list*) * max_level);
+ }
+
+ traverse_list = list_array[curr_level - 1];
+
+ for (i = (curr_level - 1);i >= 0;i--)
+ {
+ if (j > 0)
+ {
+ while (j > 0)
+ {
+ traverse_list = traverse_list->getnext();
+ --j;
+ }
+ }
+
+ while (traverse_list != NULL && (traverse_list->getval()) != key)
+ {
+ cout<<"In loop 2"<<" "<<(traverse_list->getval())<<endl;
+ ++j;
+ traverse_list = traverse_list->getnext();
+ }
+
+ if (traverse_list != NULL)
+ {
+ return 1;
+ }
+
+ traverse_list = list_array[i];
+ }
+
+ return -1;
+ }
+};
+
+int main()
+{
+ srand(time(0));
+ int low = 0;
+ int high = 1;
+ int result_search = 0;
+ double dUniform = static_cast<double>(rand()) / RAND_MAX;
+ skip_list_master list1;
+ int val1 = list1.level_generate();
+
+ //list1.insert_val(1,0);
+ //list1.insert_val(2,0);
+ //list1.insert_val(4,0);
+ //list1.insert_val(7,0);
+ //list1.insert_val(6,0);
+
+ list1.insert_skip(1);
+ //list1.insert_skip(2);
+ //list1.insert_skip(3);
+ //list1.insert_skip(4);
+ //list1.insert_skip(5);
+
+
+ //list1.print_val();
+
+ result_search = list1.search_val(1);
+
+ cout<<"search result"<<" "<<result_search<<endl;
+
+ if (dUniform > 5)
+ {
+ cout<<"insertion"<<dUniform<<" "<<val1<<endl;
+ }
+ else
+ {
+ cout<<"no insertion"<<dUniform<<" "<<val1<<endl;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/test/ConcSkipListTest.cpp~
----------------------------------------------------------------------
diff --git a/test/ConcSkipListTest.cpp~ b/test/ConcSkipListTest.cpp~
new file mode 100644
index 0000000..95552ff
--- /dev/null
+++ b/test/ConcSkipListTest.cpp~
@@ -0,0 +1,294 @@
+#include "../include/QueueLock.h"
+
+class linked_list
+{
+ int val;
+ linked_list *next;
+public:
+ linked_list()
+ {
+ val = 0;
+ next = NULL;
+ }
+ int getval()
+ {
+ return val;
+ }
+
+ void setval(int a)
+ {
+ val = a;
+ }
+
+ linked_list* getnext()
+ {
+ return next;
+ }
+
+ void setnext(linked_list *val)
+ {
+ next = val;
+ }
+};
+
+class skip_list_master
+{
+ int curr_level;
+ int max_level;
+ float probability_val;
+ linked_list **list_array;
+public:
+ skip_list_master()
+ {
+ curr_level = 0;
+ max_level = 5;
+ list_array = NULL;
+ probability_val = 0.25;
+ }
+
+ void insert_val(int location, int index, linked_list *temp)
+ {
+ linked_list *traverse = NULL;
+ int i = 0;
+
+ if (list_array == NULL)
+ {
+ list_array = (linked_list**)malloc(sizeof(linked_list*));
+ list_array[0] = temp;
+ curr_level = 1;
+
+ cout<<"Inserted condition 1"<<" "<<list_array[0]->getval()<<endl;
+
+ return;
+ }
+
+ i = index;
+ traverse = list_array[location];
+
+ /*while((traverse->getnext()) != NULL && (traverse->getval()) < a && ((traverse->getnext())->getval()) < a)
+ {
+ cout<<"In loop"<<endl;
+ traverse = traverse->getnext();
+ }*/
+
+ while (i > 0)
+ {
+ traverse = traverse->getnext();
+ --i;
+ }
+
+ if ((traverse->getnext()) == NULL)
+ {
+ traverse->setnext(temp);
+ return;
+ }
+ /*else if ((traverse->getval()) >= a)
+ {
+ temp->setnext(traverse);
+ return;
+ }*/
+
+ temp->setnext(traverse->getnext());
+ traverse->setnext(temp);
+
+ }
+
+ void insert_skip(int a)
+ {
+ linked_list **traverse_skip = NULL;
+ linked_list *traverse_list = NULL;
+ linked_list *previous_pointer = NULL;
+ linked_list *temp = NULL;
+ int i = 0;
+ int j = 0;
+ int level = 0;
+ int iteration_value = 0;
+
+ level = level_generate();
+ i = level - 1;
+
+ if (level > max_level)
+ {
+ iteration_value = max_level;
+ }
+ else
+ {
+ iteration_value = level;
+ }
+
+ temp = (linked_list*)malloc(sizeof(linked_list));
+
+ temp->setval(a);
+
+ if (!list_array)
+ {
+ insert_val(a, 0, temp);
+ return;
+ }
+ else
+ {
+ traverse_skip = (linked_list**)malloc(sizeof(linked_list*) * max_level);
+ }
+
+ traverse_list = list_array[level - 1];
+
+ for (i = (level - 1);i >= 0;i--)
+ {
+ previous_pointer = NULL;
+
+ if (j > 0)
+ {
+ while (j > 0)
+ {
+ traverse_list = traverse_list->getnext();
+ --j;
+ }
+ }
+
+ if (traverse_list == NULL)
+ {
+ cout<<"traverse_list is NULL"<<endl;
+ }
+ else
+ {
+ cout<<"traverse_list is not NULL"<<endl;
+ }
+
+ while (traverse_list != NULL && (traverse_list->getval()) < a)
+ {
+ cout<<"In loop 2"<<" "<<(traverse_list->getval())<<endl;
+ ++j;
+ previous_pointer = traverse_list;
+ traverse_list = traverse_list->getnext();
+ }
+
+ traverse_skip[i] = previous_pointer;
+
+ traverse_list = list_array[i];
+ }
+
+ insert_val(0, j, temp);
+ /*for (i = 1;i <= (level - 1);i++)
+ {*/
+
+ }
+
+
+ void print_val()
+ {
+ linked_list *traverse = NULL;
+
+ if (list_array)
+ {
+ traverse = list_array[0];
+ }
+
+ while (traverse != NULL)
+ {
+ cout<<"val is"<<" "<<traverse->getval()<<endl;
+ traverse = traverse->getnext();
+ }
+ }
+
+ int level_generate()
+ {
+ double rand_val = static_cast<double>(rand()) / RAND_MAX;
+ int level = 0;
+
+ while (rand_val > probability_val && level < max_level)
+ {
+ ++level;
+ rand_val = static_cast<double>(rand()) / RAND_MAX;
+ }
+
+ return level;
+ }
+
+ int search_val(int key)
+ {
+ linked_list **traverse_skip = NULL;
+ linked_list *traverse_list = NULL;
+ int i = 0;
+ int j = 0;
+
+ i = curr_level;
+
+ if (!list_array)
+ {
+ return 0;
+ }
+ else
+ {
+ traverse_skip = (linked_list**)malloc(sizeof(linked_list*) * max_level);
+ }
+
+ traverse_list = list_array[curr_level - 1];
+
+ for (i = (curr_level - 1);i >= 0;i--)
+ {
+ if (j > 0)
+ {
+ while (j > 0)
+ {
+ traverse_list = traverse_list->getnext();
+ --j;
+ }
+ }
+
+ while (traverse_list != NULL && (traverse_list->getval()) != key)
+ {
+ cout<<"In loop 2"<<" "<<(traverse_list->getval())<<endl;
+ ++j;
+ traverse_list = traverse_list->getnext();
+ }
+
+ if (traverse_list != NULL)
+ {
+ return 1;
+ }
+
+ traverse_list = list_array[i];
+ }
+
+ return -1;
+ }
+};
+
+int main()
+{
+ srand(time(0));
+ int low = 0;
+ int high = 1;
+ int result_search = 0;
+ double dUniform = static_cast<double>(rand()) / RAND_MAX;
+ skip_list_master list1;
+ int val1 = list1.level_generate();
+
+ //list1.insert_val(1,0);
+ //list1.insert_val(2,0);
+ //list1.insert_val(4,0);
+ //list1.insert_val(7,0);
+ //list1.insert_val(6,0);
+
+ list1.insert_skip(1);
+ //list1.insert_skip(2);
+ //list1.insert_skip(3);
+ //list1.insert_skip(4);
+ //list1.insert_skip(5);
+
+
+ //list1.print_val();
+
+ result_search = list1.search_val(1);
+
+ cout<<"search result"<<" "<<result_search<<endl;
+
+ if (dUniform > 5)
+ {
+ cout<<"insertion"<<dUniform<<" "<<val1<<endl;
+ }
+ else
+ {
+ cout<<"no insertion"<<dUniform<<" "<<val1<<endl;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/test/FileReader.cpp
----------------------------------------------------------------------
diff --git a/test/FileReader.cpp b/test/FileReader.cpp
new file mode 100644
index 0000000..e87cd19
--- /dev/null
+++ b/test/FileReader.cpp
@@ -0,0 +1,52 @@
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <string>
+#include "../include/ConcMAT.h"
+
+using namespace std;
+
+std::string line;
+std::ifstream infile("sat.trn");
+
+int main()
+{
+int count;
+int arr_val[3];
+mat_tree *tree_val = NULL;
+
+tree_val = build_mattree(3);
+count = 0;
+while (std::getline(infile, line)) // this does the checking!
+{
+ std::istringstream iss(line);
+ char c;
+
+ int value;
+ while (iss >> value)
+ {
+ if (count == 3)
+ {
+ insert_val(arr_val, tree_val);
+ count = 0;
+ cout<<"record"<<endl;
+ }
+
+ arr_val[count] = value;
+ ++count;
+ }
+}
+
+arr_val[0] = 91;
+arr_val[1] = 100;
+arr_val[2] = 81;
+
+if ((search_val(arr_val, tree_val)) != NULL)
+ {
+ cout<<"All values found"<<endl;
+ }
+ else
+ {
+ cout<<"All values not found"<<endl;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/test/FileReader.cpp~
----------------------------------------------------------------------
diff --git a/test/FileReader.cpp~ b/test/FileReader.cpp~
new file mode 100644
index 0000000..3e924fc
--- /dev/null
+++ b/test/FileReader.cpp~
@@ -0,0 +1,52 @@
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <string>
+#include "../ConcMAT.h"
+
+using namespace std;
+
+std::string line;
+std::ifstream infile("sat.trn");
+
+int main()
+{
+int count;
+int arr_val[3];
+mat_tree *tree_val = NULL;
+
+tree_val = build_mattree(3);
+count = 0;
+while (std::getline(infile, line)) // this does the checking!
+{
+ std::istringstream iss(line);
+ char c;
+
+ int value;
+ while (iss >> value)
+ {
+ if (count == 3)
+ {
+ insert_val(arr_val, tree_val);
+ count = 0;
+ cout<<"record"<<endl;
+ }
+
+ arr_val[count] = value;
+ ++count;
+ }
+}
+
+arr_val[0] = 91;
+arr_val[1] = 100;
+arr_val[2] = 81;
+
+if ((search_val(arr_val, tree_val)) != NULL)
+ {
+ cout<<"All values found"<<endl;
+ }
+ else
+ {
+ cout<<"All values not found"<<endl;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/test/QueueLockTest.cpp
----------------------------------------------------------------------
diff --git a/test/QueueLockTest.cpp b/test/QueueLockTest.cpp
new file mode 100644
index 0000000..1b28d40
--- /dev/null
+++ b/test/QueueLockTest.cpp
@@ -0,0 +1,43 @@
+#include<unistd.h>
+#include "../include/QueueLock.h"
+
+QueueLock GlobalQueueLock;
+void *thread_getlock_start(void *arg1)
+{
+ GlobalQueueLock.GetLock();
+ cout<<"Lock acquired by"<<" "<<(char*)arg1<<endl;
+ usleep(1);
+ GlobalQueueLock.ReleaseLock();
+}
+
+int main()
+{
+ int data_value = 5;
+ QueueLock lock1;
+ pthread_t tid1;
+ pthread_t tid2;
+ pthread_t tid3;
+ pthread_t tid4;
+ pthread_t tid5;
+ pthread_t tid6;
+ pthread_t tid7;
+ char name1[] = "thread1";
+ char name2[] = "thread2";
+ char name3[] = "thread3";
+ char name4[] = "thread4";
+ char name5[] = "thread5";
+
+ pthread_create(&tid1,NULL,thread_getlock_start,(void*)(name1));
+ pthread_create(&tid2,NULL,thread_getlock_start,(void*)(name2));
+ pthread_create(&tid3,NULL,thread_getlock_start,(void*)(name3));
+ pthread_create(&tid4,NULL,thread_getlock_start,(void*)(name4));
+ pthread_create(&tid5,NULL,thread_getlock_start,(void*)(name5));
+
+ pthread_join(tid1,NULL);
+ pthread_join(tid2,NULL);
+ pthread_join(tid3,NULL);
+ pthread_join(tid4,NULL);
+ pthread_join(tid5,NULL);
+}
+
+
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/test/QueueLockTest.cpp~
----------------------------------------------------------------------
diff --git a/test/QueueLockTest.cpp~ b/test/QueueLockTest.cpp~
new file mode 100644
index 0000000..2e48f69
--- /dev/null
+++ b/test/QueueLockTest.cpp~
@@ -0,0 +1,43 @@
+#include<unistd.h>
+#include "../QueueLock.h"
+
+QueueLock GlobalQueueLock;
+void *thread_getlock_start(void *arg1)
+{
+ GlobalQueueLock.GetLock();
+ cout<<"Lock acquired by"<<" "<<(char*)arg1<<endl;
+ usleep(1);
+ GlobalQueueLock.ReleaseLock();
+}
+
+int main()
+{
+ int data_value = 5;
+ QueueLock lock1;
+ pthread_t tid1;
+ pthread_t tid2;
+ pthread_t tid3;
+ pthread_t tid4;
+ pthread_t tid5;
+ pthread_t tid6;
+ pthread_t tid7;
+ char name1[] = "thread1";
+ char name2[] = "thread2";
+ char name3[] = "thread3";
+ char name4[] = "thread4";
+ char name5[] = "thread5";
+
+ pthread_create(&tid1,NULL,thread_getlock_start,(void*)(name1));
+ pthread_create(&tid2,NULL,thread_getlock_start,(void*)(name2));
+ pthread_create(&tid3,NULL,thread_getlock_start,(void*)(name3));
+ pthread_create(&tid4,NULL,thread_getlock_start,(void*)(name4));
+ pthread_create(&tid5,NULL,thread_getlock_start,(void*)(name5));
+
+ pthread_join(tid1,NULL);
+ pthread_join(tid2,NULL);
+ pthread_join(tid3,NULL);
+ pthread_join(tid4,NULL);
+ pthread_join(tid5,NULL);
+}
+
+
[2/2] incubator-concerted git commit: Restructure source directory to
a more modular hierarchy. Patch by Anand Rathi. Reviewed by Atri Sharma
Posted by at...@apache.org.
Restructure source directory to a more modular hierarchy. Patch by Anand Rathi. Reviewed by Atri Sharma
Project: http://git-wip-us.apache.org/repos/asf/incubator-concerted/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-concerted/commit/fa6ba986
Tree: http://git-wip-us.apache.org/repos/asf/incubator-concerted/tree/fa6ba986
Diff: http://git-wip-us.apache.org/repos/asf/incubator-concerted/diff/fa6ba986
Branch: refs/heads/master
Commit: fa6ba9867cee1448b79306863e8169a36fba8913
Parents: 5adf3c4
Author: Atri <at...@gmail.com>
Authored: Fri Oct 23 15:56:39 2015 +0530
Committer: Atri <at...@gmail.com>
Committed: Fri Oct 23 15:56:39 2015 +0530
----------------------------------------------------------------------
Design Documents/Hash Table design | 65 ------
Design Documents/skip lists tests | 15 --
Design/Hash Table design | 65 ++++++
Design/skip lists tests | 15 ++
Tests/ConcDCTConcurrencyTest.cpp | 72 -------
Tests/ConcDCTFileReader.cpp | 53 -----
Tests/ConcDCTTest.cpp | 62 ------
Tests/ConcInvertedIndexTest.cpp | 28 ---
Tests/ConcMATFileReader.cpp | 52 -----
Tests/ConcMATTest.cpp | 24 ---
Tests/ConcSegHashTableTest.cpp | 87 --------
Tests/ConcSkipListTest.cpp | 294 ---------------------------
Tests/FileReader.cpp | 52 -----
Tests/QueueLockTest.cpp | 43 ----
include/CacheManager.h | 36 ++++
include/ConcDCT.h | 348 ++++++++++++++++++++++++++++++++
include/ConcDef.h | 11 +
include/ConcInvertedIndex.h | 301 +++++++++++++++++++++++++++
include/ConcMAT.h | 193 ++++++++++++++++++
include/ConcQueue.h | 239 ++++++++++++++++++++++
include/ConcSegHashTable.h | 221 ++++++++++++++++++++
include/QueueLock.h | 122 +++++++++++
include/QueueLock2.h | 122 +++++++++++
include/TransactionManager.h | 229 +++++++++++++++++++++
makefile | 14 +-
src/CacheManager.h | 36 ----
src/ConcDCT.h | 348 --------------------------------
src/ConcDef.h | 11 -
src/ConcInvertedIndex.h | 301 ---------------------------
src/ConcMAT.h | 193 ------------------
src/ConcQueue.h | 239 ----------------------
src/ConcSegHashTable.h | 221 --------------------
src/QueueLock.h | 122 -----------
src/QueueLock2.h | 122 -----------
src/TransactionManager.h | 229 ---------------------
test/ConcDCTConcurrencyTest.cpp | 72 +++++++
test/ConcDCTFileReader.cpp | 53 +++++
test/ConcDCTFileReader.cpp~ | 53 +++++
test/ConcDCTTest.cpp | 62 ++++++
test/ConcDCTTest.cpp~ | 62 ++++++
test/ConcInvertedIndexTest.cpp | 28 +++
test/ConcInvertedIndexTest.cpp~ | 28 +++
test/ConcMATFileReader.cpp | 52 +++++
test/ConcMATTest.cpp | 24 +++
test/ConcMATTest.cpp~ | 24 +++
test/ConcSegHashTableTest.cpp | 87 ++++++++
test/ConcSegHashTableTest.cpp~ | 87 ++++++++
test/ConcSkipListTest.cpp | 294 +++++++++++++++++++++++++++
test/ConcSkipListTest.cpp~ | 294 +++++++++++++++++++++++++++
test/FileReader.cpp | 52 +++++
test/FileReader.cpp~ | 52 +++++
test/QueueLockTest.cpp | 43 ++++
test/QueueLockTest.cpp~ | 43 ++++
53 files changed, 3319 insertions(+), 2676 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/Design Documents/Hash Table design
----------------------------------------------------------------------
diff --git a/Design Documents/Hash Table design b/Design Documents/Hash Table design
deleted file mode 100644
index 51dd4b6..0000000
--- a/Design Documents/Hash Table design
+++ /dev/null
@@ -1,65 +0,0 @@
-Read and Write lock queues per bucket.
-
-The queues are global.
-
-Lock location = segment index + position
-
-ReadValue
-{
- Check if write lock is taken.
- if (lock taken)
- {
- Spin waiting for write lock to be released.
- }
-
- get read lock
- read value
- release read lock
-
- return (value)
-}
-
-int GetReadLock(int seg_index, int pos)
-{
- get write lock queue for the corresponding bucket.
- Check if write lock is taken
- if(lock taken)
- {
- spin waiting for lock to be released
- }
-
- get corresponding read lock queue for the corrosponding bucket.
- get read lock
-
- return 1
-}
-
-int GetWriteLock(int seg_index, int pos)
-{
- get read lock queue for the corresponding bucket.
- Check if read lock is taken.
- if(lock_taken)
- {
- spin waiting for lock to be released
- }
-
- get corresponding write lock queue for the corresponding bucket
- get write lock
-
- return 1
-}
-
-Insertion:
-
-1) If pos given by hash function in any segment is 0; return 1;
-2) If(not 1 && ReplaceValue == true)
- {
- replace in the first segment;
- return 1;
- }
-3) If(not 1 && ReplaceValue == false)
- {
- open addressing to insert value in any segment.
- if insertion not possible, return 0;
- else return 1;
- }
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/Design Documents/skip lists tests
----------------------------------------------------------------------
diff --git a/Design Documents/skip lists tests b/Design Documents/skip lists tests
deleted file mode 100644
index 2e5f46a..0000000
--- a/Design Documents/skip lists tests
+++ /dev/null
@@ -1,15 +0,0 @@
-12345 -- insert
- display
-
-make skip lists
-print
-
-insert at end
-make skip lists
-
-insert at beginning
-make skip lists
-
-insert in middle
-make skip lists
-
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/Design/Hash Table design
----------------------------------------------------------------------
diff --git a/Design/Hash Table design b/Design/Hash Table design
new file mode 100644
index 0000000..51dd4b6
--- /dev/null
+++ b/Design/Hash Table design
@@ -0,0 +1,65 @@
+Read and Write lock queues per bucket.
+
+The queues are global.
+
+Lock location = segment index + position
+
+ReadValue
+{
+ Check if write lock is taken.
+ if (lock taken)
+ {
+ Spin waiting for write lock to be released.
+ }
+
+ get read lock
+ read value
+ release read lock
+
+ return (value)
+}
+
+int GetReadLock(int seg_index, int pos)
+{
+ get write lock queue for the corresponding bucket.
+ Check if write lock is taken
+ if(lock taken)
+ {
+ spin waiting for lock to be released
+ }
+
+ get corresponding read lock queue for the corrosponding bucket.
+ get read lock
+
+ return 1
+}
+
+int GetWriteLock(int seg_index, int pos)
+{
+ get read lock queue for the corresponding bucket.
+ Check if read lock is taken.
+ if(lock_taken)
+ {
+ spin waiting for lock to be released
+ }
+
+ get corresponding write lock queue for the corresponding bucket
+ get write lock
+
+ return 1
+}
+
+Insertion:
+
+1) If pos given by hash function in any segment is 0; return 1;
+2) If(not 1 && ReplaceValue == true)
+ {
+ replace in the first segment;
+ return 1;
+ }
+3) If(not 1 && ReplaceValue == false)
+ {
+ open addressing to insert value in any segment.
+ if insertion not possible, return 0;
+ else return 1;
+ }
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/Design/skip lists tests
----------------------------------------------------------------------
diff --git a/Design/skip lists tests b/Design/skip lists tests
new file mode 100644
index 0000000..2e5f46a
--- /dev/null
+++ b/Design/skip lists tests
@@ -0,0 +1,15 @@
+12345 -- insert
+ display
+
+make skip lists
+print
+
+insert at end
+make skip lists
+
+insert at beginning
+make skip lists
+
+insert in middle
+make skip lists
+
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/Tests/ConcDCTConcurrencyTest.cpp
----------------------------------------------------------------------
diff --git a/Tests/ConcDCTConcurrencyTest.cpp b/Tests/ConcDCTConcurrencyTest.cpp
deleted file mode 100644
index ed775bb..0000000
--- a/Tests/ConcDCTConcurrencyTest.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-#include "../ConcDCT.h"
-
- void *thread_lock_test1(void *arg1)
- {
- dct_tree *tree_val = (dct_tree*)arg1;
- int arr_val[3];
-
- arr_val[0] = 1;
- arr_val[1] = 2;
- arr_val[2] = 3;
-
- insert_val(arr_val, tree_val);
- }
-
- void *thread_lock_test2(void *arg1)
- {
- dct_tree *tree_val = (dct_tree*)arg1;
- int arr_val[3];
-
- arr_val[0] = 4;
- arr_val[1] = 5;
- arr_val[2] = 6;
-
- insert_val(arr_val, tree_val);
- }
-
- void *thread_lock_test3(void *arg1)
- {
- dct_tree *tree_val = (dct_tree*)arg1;
- int arr_val[3];
-
- arr_val[0] = 1;
- arr_val[1] = 2;
- arr_val[2] = 3;
-
- insert_val(arr_val, tree_val);
- }
-
- void *thread_lock_test4(void *arg1)
- {
- dct_tree *tree_val = (dct_tree*)arg1;
- int arr_val[3];
-
- arr_val[0] = 4;
- arr_val[1] = 5;
- arr_val[2] = 6;
-
- search_val(arr_val, tree_val);
- }
-
- int main()
- {
- dct_tree *tree_val = NULL;
- pthread_t tid1;
- pthread_t tid2;
- pthread_t tid3;
- pthread_t tid4;
-
- tree_val = new dct_tree(3);
-
- pthread_create(&tid1,NULL,thread_lock_test1,(void*)tree_val);
- pthread_create(&tid2,NULL,thread_lock_test2,(void*)tree_val);
- pthread_create(&tid3,NULL,thread_lock_test3,(void*)tree_val);
- pthread_create(&tid4,NULL,thread_lock_test4,(void*)tree_val);
-
- pthread_join(tid1,NULL);
- pthread_join(tid2,NULL);
- pthread_join(tid3,NULL);
- pthread_join(tid4,NULL);
- }
-
-
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/Tests/ConcDCTFileReader.cpp
----------------------------------------------------------------------
diff --git a/Tests/ConcDCTFileReader.cpp b/Tests/ConcDCTFileReader.cpp
deleted file mode 100644
index 5e4d6c5..0000000
--- a/Tests/ConcDCTFileReader.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-#include <iostream>
-#include <sstream>
-#include <fstream>
-#include <string>
-#include "../ConcDCT.h"
-
-using namespace std;
-
-std::string line;
-std::ifstream infile("sat.trn");
-
-int main()
-{
-int count;
-int arr_val[3];
-dct_tree *tree_val = NULL;
-TransactionManager t1;
-
-tree_val = build_dcttree(3);
-count = 0;
-while (std::getline(infile, line)) // this does the checking!
-{
- std::istringstream iss(line);
- char c;
-
- int value;
- while (iss >> value)
- {
- if (count == 3)
- {
- insert_val(arr_val, tree_val, t1);
- count = 0;
- cout<<"record"<<endl;
- }
-
- arr_val[count] = value;
- ++count;
- }
-}
-
-arr_val[0] = 91;
-arr_val[1] = 100;
-arr_val[2] = 81;
-
-if ((search_val(arr_val, tree_val)) != NULL)
- {
- cout<<"All values found"<<endl;
- }
- else
- {
- cout<<"All values not found"<<endl;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/Tests/ConcDCTTest.cpp
----------------------------------------------------------------------
diff --git a/Tests/ConcDCTTest.cpp b/Tests/ConcDCTTest.cpp
deleted file mode 100644
index 303c166..0000000
--- a/Tests/ConcDCTTest.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-#include "../ConcDCT.h"
- int main()
- {
- int att_array[3];
- int i = 0;
- TransactionManager transact_val1;
- dct_tree *tree_val = NULL;
- dct_tree *tree_val2 = NULL;
- dct_tree *tree_val3 = NULL;
- dct_node *temp = NULL;
- tree_val = build_dcttree(3);
- tree_val3 = build_dcttree(3);
- att_array[0] = 1;
- att_array[1] = 2;
- att_array[2] = 3;
- try
- {
- insert_val(att_array, tree_val, transact_val1);
- insert_val(att_array, tree_val3, transact_val1);
- //throw -1;
- transact_val1.commit_transaction();
- tree_val2 = copy_val((tree_val->getdummy()), (tree_val->getnumber_of_nodes()));
- }catch (int e)
- {
- cout<<"exception caught"<<" "<<e<<endl;
- return 1;
- }
-
- //att_array[2] = 3;
- if (search_val(att_array, tree_val))
- {
- cout<<"All values found"<<endl;
- }
- else
- {
- cout<<"All values not found"<<endl;
- }
-
- temp = search_val(att_array, tree_val2);
- if (temp != NULL)
- {
- cout<<" All values found copy tree"<<endl;
- }
- else
- {
- cout<<"All values not found copy tree"<<endl;
- }
-
- if (search_val(att_array, tree_val3))
- {
- cout<<"All values found3"<<endl;
- }
- else
- {
- cout<<"All values not found3"<<endl;
- }
-
- delete tree_val;
- delete tree_val2;
- delete tree_val3;
- delete temp;
- }
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/Tests/ConcInvertedIndexTest.cpp
----------------------------------------------------------------------
diff --git a/Tests/ConcInvertedIndexTest.cpp b/Tests/ConcInvertedIndexTest.cpp
deleted file mode 100644
index 424c277..0000000
--- a/Tests/ConcInvertedIndexTest.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "../ConcInvertedIndex.h"
-
-int main()
- {
- inv_index<3,0> *index1;
- int att_values[3];
- int return_value;
-
- return_value = 0;
- index1 = new inv_index<3,0>;
- att_values[0] = 3;
- att_values[1] = 4;
- att_values[2] = 5;
-
- insert_val(att_values, index1);
-
- return_value = search_val(&(att_values[0]), index1);
-
- if (return_value == 1)
- {
- cout<<"values found"<<" "<<return_value<<endl;
- }
- else
- {
- cout<<"values not found"<<" "<<return_value<<endl;
- }
-
- }
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/Tests/ConcMATFileReader.cpp
----------------------------------------------------------------------
diff --git a/Tests/ConcMATFileReader.cpp b/Tests/ConcMATFileReader.cpp
deleted file mode 100644
index 3e924fc..0000000
--- a/Tests/ConcMATFileReader.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-#include <iostream>
-#include <sstream>
-#include <fstream>
-#include <string>
-#include "../ConcMAT.h"
-
-using namespace std;
-
-std::string line;
-std::ifstream infile("sat.trn");
-
-int main()
-{
-int count;
-int arr_val[3];
-mat_tree *tree_val = NULL;
-
-tree_val = build_mattree(3);
-count = 0;
-while (std::getline(infile, line)) // this does the checking!
-{
- std::istringstream iss(line);
- char c;
-
- int value;
- while (iss >> value)
- {
- if (count == 3)
- {
- insert_val(arr_val, tree_val);
- count = 0;
- cout<<"record"<<endl;
- }
-
- arr_val[count] = value;
- ++count;
- }
-}
-
-arr_val[0] = 91;
-arr_val[1] = 100;
-arr_val[2] = 81;
-
-if ((search_val(arr_val, tree_val)) != NULL)
- {
- cout<<"All values found"<<endl;
- }
- else
- {
- cout<<"All values not found"<<endl;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/Tests/ConcMATTest.cpp
----------------------------------------------------------------------
diff --git a/Tests/ConcMATTest.cpp b/Tests/ConcMATTest.cpp
deleted file mode 100644
index 459cdcc..0000000
--- a/Tests/ConcMATTest.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "../ConcMAT.h"
-
- int main()
- {
- int att_array[3];
- int i = 0;
- mat_tree *tree_val = NULL;
- tree_val = build_mattree(3);
- att_array[0] = 1;
- att_array[1] = 2;
- att_array[2] = 3;
- insert_val(att_array, tree_val);
- if (search_val(att_array, tree_val))
- {
- cout<<"All values found"<<endl;
- }
- else
- {
- cout<<"All values not found"<<endl;
- }
-
- delete tree_val;
- }
-
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/Tests/ConcSegHashTableTest.cpp
----------------------------------------------------------------------
diff --git a/Tests/ConcSegHashTableTest.cpp b/Tests/ConcSegHashTableTest.cpp
deleted file mode 100644
index 6a61a1a..0000000
--- a/Tests/ConcSegHashTableTest.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-#include "../ConcSegHashTable.h"
-
-ConcSegHashTable<int> tab1(10,2);
-void *thread_lock_test(void *arg1)
-{
- //tab1.GetWriteLock(0,2,(char*)arg1);
- //tab1.InsertElement(5, false, (char*)arg1);
- if((tab1.InsertElement(5, false,(char*)arg1)) == 0)
- {
- cout<<"Value not inserted"<<" "<<(char*)arg1<<" "<<5<<endl;
- sleep(1);
- }
-
- tab1.InsertElement(6, false,(char*)arg1);
- //tab1.InsertElement(5, false,(char*)arg1);
- //tab1.InsertElement(5, false,(char*)arg1);
- //cout<<"read lock with"<<" "<<(char*)arg1<<endl;
- //sleep(1);
- //tab1.ReleaseWriteLock(0,2,(char*)arg1);
- //cout<<"read lock released by"<<" "<<(char*)arg1<<endl;
-}
-
-void *thread_lock_test2(void *arg1)
-{
- //tab1.GetWriteLock(0,2, (char*)arg1);
- //cout<<"write lock with"<<" "<<(char*)arg1<<endl;
- //tab1.ReleaseWriteLock(0,2, (char*)arg1);
- //cout<<"write lock released by"<<" "<<(char*)arg1<<endl;
- if((tab1.InsertElement(5, false, (char*)arg1)) == 0)
- {
- cout<<"Value not inserted"<<" "<<(char*)arg1<<" "<<5<<endl;
- sleep(1);
- }
-
- if((tab1.InsertElement(6, false, (char*)arg1)) == 0)
- {
- cout<<"Value not inserted"<<" "<<(char*)arg1<<" "<<6<<endl;
- sleep(1);
- }
-}
-
-void *thread_lock_test3(void *arg1)
-{
- /*tab1.GetReadLock(0,2, (char*)arg1);
- cout<<"read lock with"<<" "<<(char*)arg1<<endl;
- tab1.ReleaseReadLock(0,2, (char*)arg1);
- cout<<"read lock released by"<<" "<<(char*)arg1<<endl;*/
- if((tab1.InsertElement(6, false, (char*)arg1)) == 0)
- {
- cout<<"Value not inserted"<<" "<<(char*)arg1<<" "<<6<<endl;
- }
-
- //tab1.InsertElement(6, false, (char*)arg1);
-}
-
-void *thread_lock_test4(void *arg1)
-{
- tab1.InsertElement(6,false,(char*)arg1);
- tab1.InsertElement(9,false,(char*)arg1);
-}
-
-int main()
-{
- pthread_t tid1;
- pthread_t tid2;
- pthread_t tid3;
- pthread_t tid4;
- char name1[] = "thread1";
- char name2[] = "thread2";
- char name3[] = "thread3";
- char name4[] = "thread4";
-
- pthread_create(&tid1,NULL,thread_lock_test,(void*)name1);
- pthread_create(&tid2,NULL,thread_lock_test2,(void*)name2);
- pthread_create(&tid3,NULL,thread_lock_test3,(void*)name3);
- pthread_create(&tid4,NULL,thread_lock_test4,(void*)name4);
-
- pthread_join(tid1,NULL);
- pthread_join(tid2,NULL);
- pthread_join(tid3,NULL);
- pthread_join(tid4,NULL);
-
- tab1.PrintValues();
-
- //tab1.GetWriteLock(2,3);
- //tab1.ReleaseWriteLock(2,3);
-}
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/Tests/ConcSkipListTest.cpp
----------------------------------------------------------------------
diff --git a/Tests/ConcSkipListTest.cpp b/Tests/ConcSkipListTest.cpp
deleted file mode 100644
index 83d9a5c..0000000
--- a/Tests/ConcSkipListTest.cpp
+++ /dev/null
@@ -1,294 +0,0 @@
-#include "../QueueLock.h"
-
-class linked_list
-{
- int val;
- linked_list *next;
-public:
- linked_list()
- {
- val = 0;
- next = NULL;
- }
- int getval()
- {
- return val;
- }
-
- void setval(int a)
- {
- val = a;
- }
-
- linked_list* getnext()
- {
- return next;
- }
-
- void setnext(linked_list *val)
- {
- next = val;
- }
-};
-
-class skip_list_master
-{
- int curr_level;
- int max_level;
- float probability_val;
- linked_list **list_array;
-public:
- skip_list_master()
- {
- curr_level = 0;
- max_level = 5;
- list_array = NULL;
- probability_val = 0.25;
- }
-
- void insert_val(int location, int index, linked_list *temp)
- {
- linked_list *traverse = NULL;
- int i = 0;
-
- if (list_array == NULL)
- {
- list_array = (linked_list**)malloc(sizeof(linked_list*));
- list_array[0] = temp;
- curr_level = 1;
-
- cout<<"Inserted condition 1"<<" "<<list_array[0]->getval()<<endl;
-
- return;
- }
-
- i = index;
- traverse = list_array[location];
-
- /*while((traverse->getnext()) != NULL && (traverse->getval()) < a && ((traverse->getnext())->getval()) < a)
- {
- cout<<"In loop"<<endl;
- traverse = traverse->getnext();
- }*/
-
- while (i > 0)
- {
- traverse = traverse->getnext();
- --i;
- }
-
- if ((traverse->getnext()) == NULL)
- {
- traverse->setnext(temp);
- return;
- }
- /*else if ((traverse->getval()) >= a)
- {
- temp->setnext(traverse);
- return;
- }*/
-
- temp->setnext(traverse->getnext());
- traverse->setnext(temp);
-
- }
-
- void insert_skip(int a)
- {
- linked_list **traverse_skip = NULL;
- linked_list *traverse_list = NULL;
- linked_list *previous_pointer = NULL;
- linked_list *temp = NULL;
- int i = 0;
- int j = 0;
- int level = 0;
- int iteration_value = 0;
-
- level = level_generate();
- i = level - 1;
-
- if (level > max_level)
- {
- iteration_value = max_level;
- }
- else
- {
- iteration_value = level;
- }
-
- temp = (linked_list*)malloc(sizeof(linked_list));
-
- temp->setval(a);
-
- if (!list_array)
- {
- insert_val(a, 0, temp);
- return;
- }
- else
- {
- traverse_skip = (linked_list**)malloc(sizeof(linked_list*) * max_level);
- }
-
- traverse_list = list_array[level - 1];
-
- for (i = (level - 1);i >= 0;i--)
- {
- previous_pointer = NULL;
-
- if (j > 0)
- {
- while (j > 0)
- {
- traverse_list = traverse_list->getnext();
- --j;
- }
- }
-
- if (traverse_list == NULL)
- {
- cout<<"traverse_list is NULL"<<endl;
- }
- else
- {
- cout<<"traverse_list is not NULL"<<endl;
- }
-
- while (traverse_list != NULL && (traverse_list->getval()) < a)
- {
- cout<<"In loop 2"<<" "<<(traverse_list->getval())<<endl;
- ++j;
- previous_pointer = traverse_list;
- traverse_list = traverse_list->getnext();
- }
-
- traverse_skip[i] = previous_pointer;
-
- traverse_list = list_array[i];
- }
-
- insert_val(0, j, temp);
- /*for (i = 1;i <= (level - 1);i++)
- {*/
-
- }
-
-
- void print_val()
- {
- linked_list *traverse = NULL;
-
- if (list_array)
- {
- traverse = list_array[0];
- }
-
- while (traverse != NULL)
- {
- cout<<"val is"<<" "<<traverse->getval()<<endl;
- traverse = traverse->getnext();
- }
- }
-
- int level_generate()
- {
- double rand_val = static_cast<double>(rand()) / RAND_MAX;
- int level = 0;
-
- while (rand_val > probability_val && level < max_level)
- {
- ++level;
- rand_val = static_cast<double>(rand()) / RAND_MAX;
- }
-
- return level;
- }
-
- int search_val(int key)
- {
- linked_list **traverse_skip = NULL;
- linked_list *traverse_list = NULL;
- int i = 0;
- int j = 0;
-
- i = curr_level;
-
- if (!list_array)
- {
- return 0;
- }
- else
- {
- traverse_skip = (linked_list**)malloc(sizeof(linked_list*) * max_level);
- }
-
- traverse_list = list_array[curr_level - 1];
-
- for (i = (curr_level - 1);i >= 0;i--)
- {
- if (j > 0)
- {
- while (j > 0)
- {
- traverse_list = traverse_list->getnext();
- --j;
- }
- }
-
- while (traverse_list != NULL && (traverse_list->getval()) != key)
- {
- cout<<"In loop 2"<<" "<<(traverse_list->getval())<<endl;
- ++j;
- traverse_list = traverse_list->getnext();
- }
-
- if (traverse_list != NULL)
- {
- return 1;
- }
-
- traverse_list = list_array[i];
- }
-
- return -1;
- }
-};
-
-int main()
-{
- srand(time(0));
- int low = 0;
- int high = 1;
- int result_search = 0;
- double dUniform = static_cast<double>(rand()) / RAND_MAX;
- skip_list_master list1;
- int val1 = list1.level_generate();
-
- //list1.insert_val(1,0);
- //list1.insert_val(2,0);
- //list1.insert_val(4,0);
- //list1.insert_val(7,0);
- //list1.insert_val(6,0);
-
- list1.insert_skip(1);
- //list1.insert_skip(2);
- //list1.insert_skip(3);
- //list1.insert_skip(4);
- //list1.insert_skip(5);
-
-
- //list1.print_val();
-
- result_search = list1.search_val(1);
-
- cout<<"search result"<<" "<<result_search<<endl;
-
- if (dUniform > 5)
- {
- cout<<"insertion"<<dUniform<<" "<<val1<<endl;
- }
- else
- {
- cout<<"no insertion"<<dUniform<<" "<<val1<<endl;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/Tests/FileReader.cpp
----------------------------------------------------------------------
diff --git a/Tests/FileReader.cpp b/Tests/FileReader.cpp
deleted file mode 100644
index 3e924fc..0000000
--- a/Tests/FileReader.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-#include <iostream>
-#include <sstream>
-#include <fstream>
-#include <string>
-#include "../ConcMAT.h"
-
-using namespace std;
-
-std::string line;
-std::ifstream infile("sat.trn");
-
-int main()
-{
-int count;
-int arr_val[3];
-mat_tree *tree_val = NULL;
-
-tree_val = build_mattree(3);
-count = 0;
-while (std::getline(infile, line)) // this does the checking!
-{
- std::istringstream iss(line);
- char c;
-
- int value;
- while (iss >> value)
- {
- if (count == 3)
- {
- insert_val(arr_val, tree_val);
- count = 0;
- cout<<"record"<<endl;
- }
-
- arr_val[count] = value;
- ++count;
- }
-}
-
-arr_val[0] = 91;
-arr_val[1] = 100;
-arr_val[2] = 81;
-
-if ((search_val(arr_val, tree_val)) != NULL)
- {
- cout<<"All values found"<<endl;
- }
- else
- {
- cout<<"All values not found"<<endl;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/Tests/QueueLockTest.cpp
----------------------------------------------------------------------
diff --git a/Tests/QueueLockTest.cpp b/Tests/QueueLockTest.cpp
deleted file mode 100644
index 2e48f69..0000000
--- a/Tests/QueueLockTest.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-#include<unistd.h>
-#include "../QueueLock.h"
-
-QueueLock GlobalQueueLock;
-void *thread_getlock_start(void *arg1)
-{
- GlobalQueueLock.GetLock();
- cout<<"Lock acquired by"<<" "<<(char*)arg1<<endl;
- usleep(1);
- GlobalQueueLock.ReleaseLock();
-}
-
-int main()
-{
- int data_value = 5;
- QueueLock lock1;
- pthread_t tid1;
- pthread_t tid2;
- pthread_t tid3;
- pthread_t tid4;
- pthread_t tid5;
- pthread_t tid6;
- pthread_t tid7;
- char name1[] = "thread1";
- char name2[] = "thread2";
- char name3[] = "thread3";
- char name4[] = "thread4";
- char name5[] = "thread5";
-
- pthread_create(&tid1,NULL,thread_getlock_start,(void*)(name1));
- pthread_create(&tid2,NULL,thread_getlock_start,(void*)(name2));
- pthread_create(&tid3,NULL,thread_getlock_start,(void*)(name3));
- pthread_create(&tid4,NULL,thread_getlock_start,(void*)(name4));
- pthread_create(&tid5,NULL,thread_getlock_start,(void*)(name5));
-
- pthread_join(tid1,NULL);
- pthread_join(tid2,NULL);
- pthread_join(tid3,NULL);
- pthread_join(tid4,NULL);
- pthread_join(tid5,NULL);
-}
-
-
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/include/CacheManager.h
----------------------------------------------------------------------
diff --git a/include/CacheManager.h b/include/CacheManager.h
new file mode 100644
index 0000000..4c137f3
--- /dev/null
+++ b/include/CacheManager.h
@@ -0,0 +1,36 @@
+#include <iostream>
+#include "ConcDef.h"
+using namespace std;
+
+class CacheManager
+{
+ ConcertedDef *val_array[10];
+ int current_counter;
+public:
+ CacheManager()
+ {
+ int i = 0;
+
+ for (i = 0;i < 10;i++)
+ {
+ val_array[i] = NULL;
+ }
+
+ current_counter = 0;
+ }
+
+ virtual ConcertedDef* search_val(...);
+
+ void add_val(ConcertedDef *val)
+ {
+ if (current_counter < 10)
+ {
+ val_array[current_counter] = val;
+ ++current_counter;
+
+ return;
+ }
+
+ val_array[0] = val;
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/include/ConcDCT.h
----------------------------------------------------------------------
diff --git a/include/ConcDCT.h b/include/ConcDCT.h
new file mode 100644
index 0000000..59a4e34
--- /dev/null
+++ b/include/ConcDCT.h
@@ -0,0 +1,348 @@
+#include <iostream>
+#include "TransactionManager.h"
+using namespace std;
+
+class dct_node:public ConcertedDef
+{
+ int value;
+ int level;
+ int current_insertion_index;
+ dct_node *child_pointer;
+ dct_node *next;
+ QueueLock *read_lock_val;
+ QueueLock *write_lock_val;
+public:
+ dct_node()
+ {
+ value = 0;
+ level = 0;
+ current_insertion_index = 0;
+ child_pointer = NULL;
+ next = NULL;
+ read_lock_val = new QueueLock;
+ write_lock_val = new QueueLock;
+ }
+
+ void copy_pointer_val(ConcertedDef *copy_val1)
+ {
+ dct_node *copy_val = (dct_node*)copy_val1;
+ *this = *copy_val;
+ }
+
+ int getval()
+ {
+ return value;
+ }
+
+ void setval(int a)
+ {
+ value = a;
+ }
+
+ int getlevel()
+ {
+ return level;
+ }
+
+ void setlevel(int a)
+ {
+ level = a;
+ }
+
+ void insert(dct_node *pointer_val)
+ {
+ dct_node *traverse = NULL;
+
+ if (child_pointer == NULL)
+ {
+ child_pointer = pointer_val;
+ return;
+ }
+
+ traverse = child_pointer;
+
+ while ((traverse->getnext()) != NULL)
+ {
+ traverse = traverse->getnext();
+ }
+
+ traverse->setnext(pointer_val);
+
+ }
+
+ dct_node* get_child_pointer()
+ {
+ return child_pointer;
+ }
+
+ void setnext(dct_node *next_element_pointer)
+ {
+ next = next_element_pointer;
+ }
+
+ dct_node* getnext()
+ {
+ return next;
+ }
+
+ QueueLock* getread_lock_val()
+ {
+ return read_lock_val;
+ }
+
+ QueueLock* getwrite_lock_val()
+ {
+ return write_lock_val;
+ }
+
+ ~dct_node()
+ {
+ dct_node *traverse = child_pointer;
+ dct_node *temp = NULL;
+
+ if (child_pointer != NULL)
+ {
+ temp = child_pointer->getnext();
+ }
+
+ while (traverse != NULL)
+ {
+ if (child_pointer != NULL)
+ {
+ delete child_pointer;
+ }
+
+ traverse = temp;
+ if (traverse != NULL)
+ {
+ temp = traverse->getnext();
+ }
+
+ }
+
+ }
+};
+
+class dct_tree
+{
+ dct_node *dummy;
+ int number_of_nodes;
+public:
+ dct_tree(int n)
+ {
+ dummy = new dct_node;
+ dummy->setlevel(0);
+ number_of_nodes = n;
+ }
+
+ dct_tree(dct_node *val, int n)
+ {
+ dummy = val;
+ dummy->setlevel(0);
+ number_of_nodes = n;
+ }
+
+ dct_node* getdummy()
+ {
+ return dummy;
+ }
+
+ int getnumber_of_nodes()
+ {
+ return number_of_nodes;
+ }
+
+ ~dct_tree()
+ {
+ delete dummy;
+ }
+
+};
+
+ dct_node* search_val(int[3], dct_node*);
+ dct_node* search_node(int, dct_node*);
+ dct_node* insert_val(int[3], dct_node*);
+ dct_tree* build_dcttree();
+
+ dct_tree* build_dcttree(int n)
+ {
+ dct_tree *tree_val = NULL;
+
+ tree_val = new dct_tree(n);
+
+ return tree_val;
+ }
+
+ dct_node* search_node(int val, dct_node *parent_pointer, int locksTaken)
+ {
+ dct_node *head = NULL;
+ dct_node *traverse = NULL;
+ QueueLock *write_lock_val = parent_pointer->getwrite_lock_val();
+ QueueLock *read_lock_val = parent_pointer->getread_lock_val();
+
+ if (locksTaken == 0)
+ {
+ while ((write_lock_val->CheckLockIsAcquired()) == 1)
+ {
+ cout<<"Waiting for write lock release1"<<endl;
+ }
+
+ }
+
+ if (locksTaken == 0)
+ {
+ read_lock_val->GetLock();
+ }
+
+ if (parent_pointer == NULL)
+ {
+ return NULL;
+ }
+
+ head = parent_pointer->get_child_pointer();
+ if (locksTaken == 0)
+ {
+ read_lock_val->ReleaseLock();
+ }
+
+ traverse = head;
+
+ while (traverse != NULL)
+ {
+ write_lock_val = traverse->getwrite_lock_val();
+ read_lock_val = traverse->getread_lock_val();
+
+ while ((write_lock_val->CheckLockIsAcquired()) == 1)
+ {
+ }
+
+ if (locksTaken == 0)
+ {
+ read_lock_val->GetLock();
+ }
+
+ if ((traverse->getval()) == val)
+ {
+ cout<<"value found search"<<" "<<traverse->getval()<<" "<<val<<endl;
+ return traverse;
+ }
+
+ if (locksTaken == 0)
+ {
+ read_lock_val->ReleaseLock();
+ }
+
+ traverse = traverse->getnext();
+ }
+
+ cout<<"value not found"<<endl;
+ return NULL;
+ }
+
+ dct_node* search_val(int search_val_array[3], dct_tree *tree_val)
+ {
+ dct_node *dummy = tree_val->getdummy();
+ dct_node *traverse = dummy;
+ dct_node *temp = NULL;
+ int i = 0;
+ int current_value = 0;
+
+ for (i = 0;i < (tree_val->getnumber_of_nodes());i++)
+ {
+ current_value = search_val_array[i];
+ temp = search_node(current_value, traverse,1);
+ if (temp == NULL)
+ {
+ cout<<"value not found search val"<<" "<<current_value<<endl;
+ return NULL;
+ }
+
+ traverse = temp;
+ }
+
+ return traverse;
+
+ }
+
+ dct_tree* copy_val(dct_node *val, int number_of_nodes)
+ {
+ int i = 0;
+ dct_node *traverse1 = new dct_node();
+ dct_node *traverse2 = val->get_child_pointer();
+ dct_node *temp = NULL;
+ dct_tree *return_val = NULL;
+
+ i = val->getlevel();
+
+ traverse1->setval(val->getval());
+ traverse1->setlevel(val->getlevel());
+ for (;i < number_of_nodes;i++)
+ {
+ while (traverse2 != NULL)
+ {
+ temp = new dct_node(*(traverse2));
+ traverse1->insert(temp);
+ copy_val(temp, number_of_nodes);
+ traverse2 = traverse2->getnext();
+ }
+
+ }
+
+ return_val = new dct_tree(traverse1, number_of_nodes);
+
+ return return_val;
+
+ }
+
+ dct_node* insert_val(int val_array[3], dct_tree *tree_val, TransactionManager &transact_val1)
+ {
+ dct_tree *val1 = copy_val((tree_val->getdummy()), (tree_val->getnumber_of_nodes()));
+ dct_node *dummy = val1->getdummy();
+ dct_node *dummy2 = tree_val->getdummy();
+ dct_node *traverse = NULL;
+ dct_node *temp = NULL;
+ dct_node *temp_return = NULL;
+ QueueLock *write_lock_val = dummy->getwrite_lock_val();
+ QueueLock *read_lock_val = dummy->getread_lock_val();
+ int i = 0;
+
+ traverse = dummy;
+ transact_val1.add_commit_val(dummy2, dummy);
+ for (i = 0;i < (tree_val->getnumber_of_nodes());i++)
+ {
+ write_lock_val = traverse->getwrite_lock_val();
+ read_lock_val = traverse->getread_lock_val();
+ transact_val1.add_lock(write_lock_val);
+
+ while ((read_lock_val->CheckLockIsAcquired()) == 1)
+ {
+ }
+
+ if (!(write_lock_val->GetLock()))
+ {
+ cout<<"write lock not taken"<<endl;
+ throw -1;
+ }
+
+ temp_return = search_node(val_array[i], traverse,1);
+ if (temp_return == NULL)
+ {
+ temp = new dct_node;
+ temp->setval(val_array[i]);
+ temp->setlevel(i);
+ traverse->insert(temp);
+ write_lock_val->ReleaseLock();
+ transact_val1.delete_lock(write_lock_val);
+ traverse = temp;
+ }
+ else
+ {
+ write_lock_val->ReleaseLock();
+ transact_val1.delete_lock(write_lock_val);
+
+ traverse = temp_return;
+ }
+
+ }
+
+ }
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/include/ConcDef.h
----------------------------------------------------------------------
diff --git a/include/ConcDef.h b/include/ConcDef.h
new file mode 100644
index 0000000..c518e6c
--- /dev/null
+++ b/include/ConcDef.h
@@ -0,0 +1,11 @@
+#include <iostream>
+using namespace std;
+
+class ConcertedDef
+{
+public:
+ virtual void copy_pointer_val(ConcertedDef *copy_val1)
+ {
+ cout<<"in ConcertedDef copy_pointer_val"<<endl;
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/include/ConcInvertedIndex.h
----------------------------------------------------------------------
diff --git a/include/ConcInvertedIndex.h b/include/ConcInvertedIndex.h
new file mode 100644
index 0000000..9fbab2f
--- /dev/null
+++ b/include/ConcInvertedIndex.h
@@ -0,0 +1,301 @@
+#include<iostream>
+using namespace std;
+
+template<int n, int index> class inv_index_node
+{
+ int key;
+ int values_array[10][n-1];
+ inv_index_node<n, index> *next;
+ int number_of_attributes;
+ int index_location;
+public:
+ inv_index_node()
+ {
+ int i = 0;
+ int j = 0;
+
+ key = 0;
+
+ for(i = 0;i < n;i++)
+ {
+ for(j = 0;j < 10;j++)
+ {
+ values_array[i][j] = 0;
+ }
+
+ }
+
+ number_of_attributes = n - 1;
+ index_location = index;
+ next = NULL;
+ }
+
+ void setkey(int val)
+ {
+ key = val;
+ }
+
+ int getkey()
+ {
+ return key;
+ }
+
+ void setval(int val, int row, int column)
+ {
+ values_array[row][column] = val;
+ }
+
+ int getval(int row, int column)
+ {
+ return values_array[row][column];
+ }
+
+ void setnext(inv_index_node<n, index> *val)
+ {
+ next = val;
+ }
+
+ inv_index_node<n, index>* getnext()
+ {
+ return next;
+ }
+
+ const int getnumber_of_attributes()
+ {
+ return number_of_attributes;
+ }
+
+ const int getindex_location()
+ {
+ return index_location;
+ }
+};
+
+ template<int n, int index> class inv_index
+ {
+ inv_index_node<n,index> *dummy;
+ public:
+ inv_index()
+ {
+ dummy = NULL;
+ }
+
+ inv_index_node<n,index>* get_dummy()
+ {
+ return dummy;
+ }
+
+ void insert_val(inv_index_node<n,index> *val)
+ {
+ inv_index_node<n, index> *traverse = dummy;
+
+ if (dummy == NULL)
+ {
+ dummy = val;
+ return;
+ }
+
+ while ((dummy->getnext()) != NULL)
+ {
+ dummy = dummy->getnext();
+ }
+
+ dummy->setnext(val);
+ }
+
+ };
+
+
+
+ template<int n, int index> int search_val(int *att_values, inv_index<n,index> *index_val)
+ {
+ int i = 0;
+ inv_index_node<n,index> *traverse = index_val->get_dummy();
+ int number_of_attributes = traverse->getnumber_of_attributes();
+ int index_search = *(att_values + traverse->getindex_location());
+ int return_val;
+ inv_index_node<n,index> *temp = NULL;
+
+ return_val = 0;
+
+ temp = search_list(index_search, index_val);
+
+ if (temp == NULL)
+ {
+ cout<<"value not found1"<<" "<<index_search<<endl;
+ return -1;
+ }
+
+ for (i = 1;i < n;i++)
+ {
+ if (i != index)
+ {
+ return_val = search_array_val(*(att_values + i), temp, i);
+ //return_val = search_array(&(att_values[1]), (inv_index->get_dummy()));
+
+ if (return_val == -1)
+ {
+ cout<<"value not found"<<" "<<*(att_values + i)<<" "<<i<<" "<<index<<endl;
+ return -1;
+ }
+
+ }
+
+ }
+
+ return 1;
+ }
+
+ template<int n, int index> inv_index_node<n, index>* search_list(int val, inv_index<n,index> *index_val)
+ {
+ inv_index_node<n,index> *traverse = index_val->get_dummy();
+
+ while (traverse != NULL && traverse->getkey() != val)
+ {
+ traverse = traverse->getnext();
+ }
+
+ if (traverse == NULL)
+ {
+ return NULL;
+ }
+
+ return traverse;
+ }
+
+ template<int n, int index> int search_array(int *val_array, inv_index_node<n,index> *index_node_val)
+ {
+ int i;
+ int j;
+ int found;
+
+ i = 0;
+ j = 0;
+ found = 0;
+
+ for (i = 0; i < (n - 1);i++)
+ {
+ for (j = 0;j < 10;j++)
+ {
+ if (*(val_array + i) == (index_node_val->getval(i,j)))
+ {
+ cout<<"value found"<<" "<<*(val_array + i)<<" "<<i<<" "<<j<<endl;
+ ++found;
+ break;
+ }
+ else
+ {
+ cout<<"value not found"<<" "<<*(val_array + i)<<" "<<i<<" "<<j<<endl;
+ }
+ }
+ }
+
+ if (found == (n - 1))
+ {
+ cout<<"values found"<<" "<<found<<endl;
+ return 1;
+ }
+
+ cout<<"values not found"<<" "<<found<<endl;
+ return -1;
+ }
+
+ template<int n, int index> int search_array_val(int val, inv_index_node<n, index> *index_node_val, int index_location)
+ {
+ int i = 0;
+
+ cout<<"index location value is"<<" "<<val<<" "<<index_location<<endl;
+ for (i = 0;i < 10;i++)
+ {
+ if (i != index)
+ {
+ if ((index_node_val->getval((index_location - 2), i)) == val)
+ {
+ cout<<"value found2"<<" "<<val<<" "<<i<<endl;
+ return i;
+ }
+ else
+ {
+ cout<<"value not found4"<<" "<<val<<" "<<index_node_val->getval((index_location - 2), i)<<" "<<index_location<<endl;
+ }
+
+ }
+
+ }
+
+ cout<<"value not found2"<<" "<<val<<" "<<(index_location - 2)<<endl;
+ return -1;
+ }
+
+ template<int n, int index> int insert_val_array(int val, inv_index<n, index> *index_val, int index_location)
+ {
+ int i = 0;
+ int j = 0;
+ int flag_found = 0;
+ inv_index_node<n,index> *traverse = index_val->get_dummy();
+
+ cout<<"index_location is"<<" "<<val<<" "<<index_location<<endl;
+ for (j = 0;j < 10;j++)
+ {
+ if ((traverse->getval((index_location - 1), j)) == 0)
+ {
+ cout<<"empty space found"<<" "<<(index_location - 1)<<" "<<j<<endl;
+ flag_found = 1;
+ break;
+ }
+
+ }
+
+ if (flag_found == 1)
+ {
+ traverse->setval(val, (index_location - 1), j);
+ cout<<"value inserted"<<" "<<val<<" "<<(index_location - 1)<<" "<<j<<endl;
+ return 1;
+ }
+
+ return -1;
+ }
+
+ template<int n,int index> void insert_val(int att_values[], inv_index<n, index> *index_val)
+ {
+ int i = 0;
+ int return_val = 0;
+ int return_val_2 = 0;
+ inv_index_node<n,index> *traverse = NULL;
+ inv_index_node<n,index> *temp = NULL;
+
+ traverse = search_list(*(att_values + index), index_val);
+
+ if (traverse == NULL)
+ {
+ temp = new inv_index_node<n,index>;
+ temp->setkey(*(att_values + index));
+ index_val->insert_val(temp);
+ traverse = temp;
+ }
+
+ for (i = 1;i < n;i++)
+ {
+ if (i != index)
+ {
+ return_val = search_array_val(*(att_values + i), (index_val->get_dummy()), i);
+
+ if (return_val == -1)
+ {
+ return_val_2 = insert_val_array(*(att_values + i), index_val, i);
+
+ if (return_val_2 == -1)
+ {
+ cout<<"value not inserted due to lack of space"<<endl;
+ return;
+ }
+
+ return_val = 0;
+ return_val_2 = 0;
+ }
+
+ }
+
+ }
+
+ }
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/include/ConcMAT.h
----------------------------------------------------------------------
diff --git a/include/ConcMAT.h b/include/ConcMAT.h
new file mode 100644
index 0000000..1c8dc0e
--- /dev/null
+++ b/include/ConcMAT.h
@@ -0,0 +1,193 @@
+#include<iostream>
+using namespace std;
+
+class mat_node
+{
+ int value;
+ int level;
+ int current_insertion_index;
+ mat_node *child_pointer_array[10];
+public:
+ mat_node()
+ {
+ int i = 0;
+ value = 0;
+ level = 0;
+ current_insertion_index = 0;
+ for (i = 0;i < 10;i++)
+ {
+ *(child_pointer_array + i) = NULL;
+ }
+ }
+ int getval()
+ {
+ return value;
+ }
+
+ void setval(int a)
+ {
+ value = a;
+ }
+
+ int getlevel()
+ {
+ return level;
+ }
+
+ void setlevel(int a)
+ {
+ level = a;
+ }
+
+ void insert(mat_node *pointer_val)
+ {
+ child_pointer_array[0] = pointer_val;
+ }
+
+ mat_node** get_child_pointer_array()
+ {
+ return child_pointer_array;
+ }
+
+ ~mat_node()
+ {
+ mat_node *traverse = child_pointer_array[0];
+ int i = 0;
+
+ while(traverse != NULL && i < 10)
+ {
+ delete traverse;
+ ++i;
+ traverse = *(child_pointer_array + i);
+ }
+
+ delete traverse;
+
+ }
+};
+
+ class mat_tree
+ {
+ mat_node *dummy;
+ int number_of_attributes;
+ public:
+ mat_tree(int n)
+ {
+ dummy = new mat_node;
+ dummy->setlevel(0);
+ number_of_attributes = n;
+ }
+
+ mat_node* getdummy()
+ {
+ return dummy;
+ }
+
+ int getnumber_of_attributes()
+ {
+ return number_of_attributes;
+ }
+
+ ~mat_tree()
+ {
+ delete dummy;
+ }
+ };
+
+ mat_tree* build_mattree(int);
+ mat_node* search_node(int, mat_node*, mat_node*);
+ mat_node* search_val(int[3],mat_node*);
+ mat_node* insert_val(int[3],mat_node*);
+
+ mat_tree* build_mattree(int n)
+ {
+ mat_tree* tree_val = NULL;
+
+ tree_val = new mat_tree(n);
+
+ return tree_val;
+ }
+
+ mat_node* search_node(int val, mat_node *parent_pointer, mat_node *dummy)
+ {
+ mat_node **traverse = parent_pointer->get_child_pointer_array();
+ mat_node *temp = NULL;
+ int i = 0;
+
+ if (parent_pointer == NULL)
+ {
+ cout<<"parent pointer is NULL"<<endl;
+ return NULL;
+ }
+
+ while (i < 3)
+ {
+ temp = *(traverse + i);
+ if (temp != NULL)
+ {
+ if ((temp->getval()) == val)
+ {
+ cout<<"value found"<<" "<<temp->getval()<<" "<<val<<endl;
+ return temp;
+ }
+
+ }
+
+ ++i;
+ }
+
+ cout<<"value not found"<<endl;
+ return NULL;
+ }
+
+ mat_node* search_val(int search_val_array[3], mat_tree *tree_val)
+ {
+ mat_node *dummy = tree_val->getdummy();
+ mat_node *traverse = dummy;
+ mat_node *temp = NULL;
+ int i = 0;
+ int current_value = 0;
+
+ for (i = 0;i < 3;i++)
+ {
+ current_value = search_val_array[i];
+ temp = search_node(current_value, traverse, dummy);
+ if (temp == NULL)
+ {
+ cout<<"value not found"<<" "<<current_value<<endl;
+ return NULL;
+ }
+
+ traverse = temp;
+ }
+
+ }
+
+ mat_node* insert_val(int val_array[3], mat_tree *tree_val)
+ {
+ mat_node *dummy = tree_val->getdummy();
+ mat_node *traverse = NULL;
+ mat_node *temp = NULL;
+ mat_node *temp_return = NULL;
+ int i = 0;
+
+ traverse = dummy;
+ for (i = 0;i < 3;i++)
+ {
+ temp_return = search_node(val_array[i], traverse, dummy);
+ if (temp_return == NULL)
+ {
+ temp = new mat_node;
+ temp->setval(val_array[i]);
+ temp->setlevel(i);
+ traverse->insert(temp);
+ traverse = temp;
+ }
+ else
+ {
+ traverse = temp_return;
+ }
+
+ }
+
+ }
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/include/ConcQueue.h
----------------------------------------------------------------------
diff --git a/include/ConcQueue.h b/include/ConcQueue.h
new file mode 100644
index 0000000..07dba00
--- /dev/null
+++ b/include/ConcQueue.h
@@ -0,0 +1,239 @@
+#ifndef CONCQUEUE_INCLUDED
+#define CONCQUEUE_INCLUDED
+
+#include<iostream>
+#include<stdlib.h>
+using namespace std;
+
+typedef struct {
+
+ volatile int lock_value;
+
+} lock_queue;
+
+template<class data_val_type> class QueueElement
+{
+ data_val_type data_value;
+ QueueElement *next;
+public:
+ QueueElement(data_val_type a):data_value(a),next(NULL)
+ {
+ }
+
+ data_val_type GetData() const
+ {
+ return data_value;
+ }
+
+ void SetData(data_val_type val)
+ {
+ data_value = val;
+ }
+
+ void SetPointer(QueueElement *a)
+ {
+ next = a;
+ }
+
+ QueueElement* GetPointer() const
+ {
+ return next;
+ }
+
+ const data_val_type* GetPointerToData() const
+ {
+ return (&data_value);
+ }
+};
+
+template<class data_val_type> class ConcQueue
+{
+ QueueElement<data_val_type> *head;
+ QueueElement<data_val_type> *tail;
+ lock_queue insertion_lock;
+ lock_queue deletion_lock;
+public:
+ ConcQueue():head(NULL),tail(NULL)
+ {
+ insertion_lock.lock_value = 0;
+ deletion_lock.lock_value = 0;
+ }
+
+ int CAS(volatile int *val, int compare_value, int swap_value)
+ {
+
+ return __sync_bool_compare_and_swap(val, compare_value, swap_value);
+ }
+
+ void PrintQueue()
+ {
+ const QueueElement<data_val_type> *traverse = NULL;
+
+ traverse = head;
+
+ while(traverse != NULL)
+ {
+ cout<<traverse->GetData()<<endl;
+ traverse = traverse->GetPointer();
+ }
+ }
+
+ const QueueElement<data_val_type>* AddElement(data_val_type val)
+ {
+ QueueElement<data_val_type> *temp = NULL;
+ lock_queue current_lock;
+
+ temp = new QueueElement<data_val_type>(val);
+ temp->SetPointer(NULL);
+
+ /* Synchronization by locking with compare and swap.The current value of
+ * lock is compared with the expected value(locked,unlocked) and
+ * swapped accordingly.Threads spin until they acquire the lock.
+ */
+ while(!(CAS(&(insertion_lock.lock_value), 0, 1)))
+ {
+ // Spinning waiting for lock.
+ }
+
+ if(head == NULL && tail == NULL)
+ {
+ tail = new QueueElement<data_val_type>(val);
+ head = tail;
+ CAS(&(insertion_lock.lock_value), 1 ,0);
+
+ return (head);
+ }
+ else
+ {
+ tail->SetPointer(temp);
+ tail = temp;
+ CAS(&(insertion_lock.lock_value), 1, 0);
+
+ return (temp);
+ }
+ }
+
+ const QueueElement<data_val_type>* AddElementInFront(data_val_type val) //Use with EXTREME caution.
+ {
+ QueueElement<data_val_type> *temp = NULL;
+ lock_queue current_lock;
+
+ temp = new QueueElement<data_val_type>(val);
+ temp->SetPointer(NULL);
+
+ /* Synchronization by locking with compare and swap.The current value of
+ * lock is compared with the expected value(locked,unlocked) and
+ * swapped accordingly.Threads spin until they acquire the lock.
+ */
+ while(!(CAS(&(insertion_lock.lock_value), 0, 1)))
+ {
+ // Spinning waiting for lock.
+ }
+
+ if(head == NULL && tail == NULL)
+ {
+ tail = new QueueElement<data_val_type>(val);
+ head = tail;
+ CAS(&(insertion_lock.lock_value), 1 ,0);
+
+ return (head);
+ }
+ else
+ {
+ temp->SetPointer(head);
+ head = temp;
+ }
+
+ return (temp);
+ }
+ QueueElement<data_val_type>* GetElement()
+ {
+ QueueElement<data_val_type> *current_element = head;
+ QueueElement<data_val_type> *temp = NULL;
+
+ while(!(CAS(&(deletion_lock.lock_value), 0, 1)))
+ {
+ //Spin waiting for the lock
+ }
+
+ if(head != NULL)
+ {
+ head = head->GetPointer();
+ }
+
+ CAS(&(deletion_lock.lock_value) ,1, 0);
+ /* When popping an element from the queue and returning it,the
+ * ownership of the element is changed from the queue to the
+ * calling function. Hence, the element is no longer required
+ * to be const.
+ */
+ //temp = const_cast<QueueElement<data_val_type>*> (current_element);
+ temp = current_element;
+ return (temp);
+ }
+
+ QueueElement<data_val_type>* SearchQueue(data_val_type val)
+ {
+ QueueElement<data_val_type> *traverse = head;
+
+ while (traverse != NULL)
+ {
+ if ((traverse->GetData()) == val)
+ {
+ return (traverse);
+ }
+
+ traverse = traverse->GetPointer();
+
+ }
+
+ cout<<"value not found SearchQueue"<<endl;
+
+ return NULL;
+ }
+
+ int GetToFront(QueueElement<data_val_type> val)
+ {
+ int val_found = 0;
+ QueueElement<data_val_type> *traverse = head;
+ QueueElement<data_val_type> *traverse2 = head;
+
+ while (traverse != NULL)
+ {
+ if ((traverse->GetData()) == val)
+ {
+ cout<<"value found GetToFront"<<endl;
+ val_found = 1;
+ break;
+ }
+
+ traverse2 = traverse;
+ traverse = traverse->GetPointer();
+
+ }
+
+ if (val_found == 1)
+ {
+ traverse2->SetPointer(traverse->GetPointer());
+ AddElementInFront(traverse->GetData());
+ return 1;
+ }
+
+ return -1;
+ }
+
+ ~ConcQueue()
+ {
+ QueueElement<data_val_type>* temp = head;
+
+ while(head != NULL)
+ {
+ temp = head->GetPointer();
+ delete head;
+ head = temp;
+ }
+
+ }
+};
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/include/ConcSegHashTable.h
----------------------------------------------------------------------
diff --git a/include/ConcSegHashTable.h b/include/ConcSegHashTable.h
new file mode 100644
index 0000000..764e323
--- /dev/null
+++ b/include/ConcSegHashTable.h
@@ -0,0 +1,221 @@
+#include "QueueLock.h"
+
+template<class data_val_type> class ConcSegHashTable
+{
+ data_val_type **hash_tables;
+ QueueLock *read_lock_queues;
+ QueueLock *write_lock_queues;
+ int number_of_segments;
+ int number_of_buckets;
+ int last_insert_segment;
+public:
+ ConcSegHashTable(int m,int n)
+ {
+ int i;
+ int j;
+
+ i = 0;
+ j = 0;
+ number_of_segments = n;
+ number_of_buckets = m;
+ last_insert_segment = -1;
+ hash_tables = new data_val_type*[n];
+ for(i = 0;i < n;i++)
+ {
+ *(hash_tables + i) = new data_val_type[m];
+ for(j = 0;j < m;j++)
+ {
+ *(*(hash_tables + i) + j) = 0;
+ }
+
+ }
+
+ read_lock_queues = new QueueLock[m * n];
+ write_lock_queues = new QueueLock[m * n];
+ read_lock_queues->SetTimeOutPeriod(3.0);
+ write_lock_queues->SetTimeOutPeriod(3.0);
+ }
+
+ int HashVal(data_val_type val)
+ {
+
+ return ((val/3) + 1);
+ }
+
+ int GetReadLock(int seg_index, int pos, char *name1)
+ {
+ QueueLock *current_write = write_lock_queues + (seg_index + pos);
+ QueueLock *current_read = read_lock_queues + (seg_index + pos);
+ const volatile int *p_write_lock_flag = current_write->GetPointerToFlag();
+
+ if(current_write->CheckLockIsAcquired() == 1)
+ {
+ while(*(p_write_lock_flag) != 0)
+ {
+ //Spinning waiting for write lock to release
+ }
+
+ }
+
+ return (current_read->GetLock(name1));
+ }
+
+ int GetWriteLock(int seg_index, int pos, char *name1)
+ {
+ QueueLock *current_write = write_lock_queues + (seg_index + pos);
+ QueueLock *current_read = read_lock_queues + (seg_index + pos);
+ const int *p_read_lock_flag = current_read->GetPointerToFlag();
+
+ if(current_read->CheckLockIsAcquired())
+ {
+ while(*(p_read_lock_flag) != 0)
+ {
+ //Spinning waiting for read lock to release
+ }
+
+ }
+
+ return (current_write->GetLock(name1));
+ }
+
+ void UpgradeLock(int seg_index, int pos, char *name1)
+ {
+ int i;
+
+ QueueLock *current_write = write_lock_queues + (seg_index + pos);
+
+ current_write->ForceLock(name1); //We need to immediately get a write lock in order to upgrade the lock.
+ ReleaseReadLock(name1);
+ }
+
+ void ReleaseWriteLock(int seg_index, int pos, char *name1)
+ {
+ QueueLock *current_write = write_lock_queues + (seg_index + pos);
+
+ current_write->ReleaseLock(name1);
+ cout<<"Write lock released"<<endl;
+ }
+
+ void ReleaseReadLock(int seg_index, int pos, char *name1)
+ {
+ QueueLock *current_read = read_lock_queues + (seg_index + pos);
+
+ current_read->ReleaseLock(name1);
+ }
+
+ int SegmentInsert(int seg_index, data_val_type val, int pos, bool ReplaceValue, char *name1)
+ {
+ int get_write_lock = 0;
+ int get_read_lock = 0;
+ int check_lock_status = 0;
+
+ check_lock_status = (write_lock_queues + (seg_index + pos))->CheckLockIsAcquired();
+ if(check_lock_status == 1)
+ {
+ cout<<"Lock already taken"<<endl;
+ }
+ else
+ {
+ get_write_lock = GetWriteLock(seg_index, pos, name1);
+ if(get_write_lock == 0)
+ {
+ cout<<"did not get lock"<<" "<<seg_index<<" "<<pos<<" "<<name1<<endl;
+ return (0);
+ }
+
+ if(*(*(hash_tables + seg_index) + pos) == 0 || ReplaceValue == true)
+ {
+ *(*(hash_tables + seg_index) + pos) = val;
+ ReleaseWriteLock(seg_index, pos, name1);
+
+ return (1);
+ }
+
+ }
+
+ return (0);
+ }
+
+ int InsertElement(data_val_type val, bool ReplaceValue, char *name1)
+ {
+ int i;
+ int k;
+ int j;
+ int pos = HashVal(val);
+
+ j = 0;
+
+ if(last_insert_segment == -1)
+ {
+ k = 0;
+ }
+ else
+ {
+ k = last_insert_segment;
+ }
+
+ for(i = k;i < number_of_segments;i++)
+ {
+ if(SegmentInsert(i, val, pos, false, name1) == 1)
+ {
+ cout<<"value inserted at"<<" "<<i<<" "<<pos<<endl;
+ last_insert_segment = i;
+ return 1;
+ }
+
+ }
+
+ for(i = 0;i < k;i++)
+ {
+ if(SegmentInsert(i, val, pos, false, name1) == 1)
+ {
+ cout<<"value inserted at"<<" "<<i<<" "<<pos<<endl;
+ last_insert_segment = i;
+ return 1;
+ }
+
+ }
+
+ for(i = k;i < number_of_segments;i++)
+ {
+ for(j = pos;j < number_of_buckets;j++)
+ {
+ if(SegmentInsert(i, val, j, false, name1) == 1)
+ {
+ cout<<"value inserted open addressing"<<" "<<i<<" "<<j<<endl;
+ return (1);
+ }
+
+ }
+
+ }
+
+ return (0);
+ }
+
+ void PrintValues()
+ {
+ int i;
+ int j;
+
+ i = 0;
+ j = 0;
+
+ for(i = 0;i < number_of_segments;i++)
+ {
+ for(j = 0;j < number_of_buckets;j++)
+ {
+ cout<<i<<" "<<j<<" "<<*(*(hash_tables + i) + j)<<endl;
+ }
+
+ }
+
+ }
+ ~ConcSegHashTable()
+ {
+ delete hash_tables[number_of_segments];
+ delete[] read_lock_queues;
+ delete[] write_lock_queues;
+ }
+
+};
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/include/QueueLock.h
----------------------------------------------------------------------
diff --git a/include/QueueLock.h b/include/QueueLock.h
new file mode 100644
index 0000000..e7549b8
--- /dev/null
+++ b/include/QueueLock.h
@@ -0,0 +1,122 @@
+#include "ConcQueue.h"
+#include <ctime>
+
+#define BILLION 1E9
+
+class QueueLock
+{
+ ConcQueue<int> lock_queue;
+ int lock_taken;
+ int number_of_elements;
+ float timeout_period;
+public:
+ QueueLock():lock_taken(0),number_of_elements(0),timeout_period(3.0)
+ {
+ }
+
+ int GetLock(char *name1)
+ {
+ struct timespec requestStart, requestEnd;
+ if(lock_taken != 0)
+ {
+ const QueueElement<int> *p_add = lock_queue.AddElement(0);
+ ++number_of_elements;
+ const volatile int *p_spin = p_add->GetPointerToData();
+
+ clock_gettime(CLOCK_REALTIME, &requestStart);
+
+ while(*(p_spin) != 1)
+ {
+ //Spinning waiting for lock
+ clock_gettime(CLOCK_REALTIME, &requestEnd);
+
+ double accum = ( requestEnd.tv_sec - requestStart.tv_sec )
+ + ( requestEnd.tv_nsec - requestStart.tv_nsec )
+ / BILLION;
+
+ if(accum >= timeout_period)
+ {
+ break;
+ return (0);
+ }
+
+ }
+
+ }
+
+ lock_taken = 1;
+
+ return (1);
+ }
+
+ void ReleaseLock(char *name1)
+ {
+ QueueElement<int> *p_release = lock_queue.GetElement();
+
+ if(p_release == NULL)
+ {
+ lock_taken = 0;
+ }
+ else
+ {
+ --number_of_elements;
+ p_release->SetData(1);
+ }
+
+ }
+
+ int ForceLock(char *name1) //Use with EXTREME caution.
+ {
+ const QueueElement<int> *p_add = lock_queue.AddElementInFront(0);
+ const int *p_spin = p_add->GetPointerToData();
+ struct timespec requestStart, requestEnd;
+
+ if(lock_taken != 0)
+ {
+ clock_gettime(CLOCK_REALTIME, &requestStart);
+
+ while(*(p_spin) != 1)
+ {
+ //Spinning waiting for lock
+ clock_gettime(CLOCK_REALTIME, &requestEnd);
+
+ double accum = ( requestEnd.tv_sec - requestStart.tv_sec )
+ + ( requestEnd.tv_nsec - requestStart.tv_nsec )
+ / BILLION;
+
+ if(accum >= timeout_period)
+ {
+ break;
+ return (0);
+ }
+
+ }
+
+ }
+
+ lock_taken = 1;
+
+ return (1);
+ }
+
+
+ int CheckLockIsAcquired()
+ {
+
+ return (lock_taken);
+ }
+
+ const int* GetPointerToFlag() const
+ {
+
+ return (&lock_taken);
+ }
+
+ void SetTimeOutPeriod(float timeout_period_val)
+ {
+ timeout_period = timeout_period_val;
+ }
+
+};
+
+
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/include/QueueLock2.h
----------------------------------------------------------------------
diff --git a/include/QueueLock2.h b/include/QueueLock2.h
new file mode 100644
index 0000000..e4ada9e
--- /dev/null
+++ b/include/QueueLock2.h
@@ -0,0 +1,122 @@
+#include "ConcQueue.h"
+#include <ctime>
+
+#define BILLION 1E9
+
+class QueueLock
+{
+ ConcQueue<int> lock_queue;
+ int lock_taken;
+ int number_of_elements;
+ float timeout_period;
+public:
+ QueueLock():lock_taken(0),number_of_elements(0),timeout_period(3.0)
+ {
+ }
+
+ int GetLock()
+ {
+ struct timespec requestStart, requestEnd;
+ if(lock_taken != 0)
+ {
+ const QueueElement<int> *p_add = lock_queue.AddElement(0);
+ ++number_of_elements;
+ const volatile int *p_spin = p_add->GetPointerToData();
+
+ clock_gettime(CLOCK_REALTIME, &requestStart);
+
+ while(*(p_spin) != 1)
+ {
+ //Spinning waiting for lock
+ clock_gettime(CLOCK_REALTIME, &requestEnd);
+
+ double accum = ( requestEnd.tv_sec - requestStart.tv_sec )
+ + ( requestEnd.tv_nsec - requestStart.tv_nsec )
+ / BILLION;
+
+ if(accum >= timeout_period)
+ {
+ break;
+ return (0);
+ }
+
+ }
+
+ }
+
+ lock_taken = 1;
+
+ return (1);
+ }
+
+ void ReleaseLock()
+ {
+ QueueElement<int> *p_release = lock_queue.GetElement();
+
+ if(p_release == NULL)
+ {
+ lock_taken = 0;
+ }
+ else
+ {
+ --number_of_elements;
+ p_release->SetData(1);
+ }
+
+ }
+
+ int ForceLock() //Use with EXTREME caution.
+ {
+ const QueueElement<int> *p_add = lock_queue.AddElementInFront(0);
+ const int *p_spin = p_add->GetPointerToData();
+ struct timespec requestStart, requestEnd;
+
+ if(lock_taken != 0)
+ {
+ clock_gettime(CLOCK_REALTIME, &requestStart);
+
+ while(*(p_spin) != 1)
+ {
+ //Spinning waiting for lock
+ clock_gettime(CLOCK_REALTIME, &requestEnd);
+
+ double accum = ( requestEnd.tv_sec - requestStart.tv_sec )
+ + ( requestEnd.tv_nsec - requestStart.tv_nsec )
+ / BILLION;
+
+ if(accum >= timeout_period)
+ {
+ break;
+ return (0);
+ }
+
+ }
+
+ }
+
+ lock_taken = 1;
+
+ return (1);
+ }
+
+
+ int CheckLockIsAcquired()
+ {
+
+ return (lock_taken);
+ }
+
+ const int* GetPointerToFlag() const
+ {
+
+ return (&lock_taken);
+ }
+
+ void SetTimeOutPeriod(float timeout_period_val)
+ {
+ timeout_period = timeout_period_val;
+ }
+
+};
+
+
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/include/TransactionManager.h
----------------------------------------------------------------------
diff --git a/include/TransactionManager.h b/include/TransactionManager.h
new file mode 100644
index 0000000..cb7c1ff
--- /dev/null
+++ b/include/TransactionManager.h
@@ -0,0 +1,229 @@
+#include <iostream>
+#include "QueueLock2.h"
+#include "ConcDef.h"
+using namespace std;
+
+class TransactionManager
+{
+ static int active_transaction_number;
+ int current_transaction_number;
+ static int counter;
+ int lock_counter;
+ int memory_counter;
+ int commit_val_counter;
+ static int active_transactions[10];
+ int delete_val;
+ ConcertedDef* current_val[10];
+ ConcertedDef* copy_val[10];
+ void *mem_allocated_val_array[10];
+ QueueLock *lock_val_array[10];
+public:
+ TransactionManager()
+ {
+ int i = 0;
+
+ for(i = 0;i < 10;i++)
+ {
+ current_val[i] = NULL;
+ copy_val[i] = NULL;
+ active_transactions[i] = 0;
+ lock_val_array[i] = NULL;
+ mem_allocated_val_array[i] = NULL;
+ }
+
+ if (counter == 10)
+ {
+ cout<<"A new transaction number cannot be inserted due to lack of space"<<endl;
+ throw -1;
+ }
+
+ current_transaction_number = ++active_transaction_number;
+ active_transactions[counter] = active_transaction_number;
+ ++counter;
+
+ lock_counter = 0;
+ memory_counter = 0;
+ commit_val_counter = 0;
+ delete_val = 1;
+ }
+
+ int add_transaction()
+ {
+
+ if (counter == 10)
+ {
+ cout<<"A new transaction number cannot be inserted due to lack of space"<<endl;
+ return -1;
+ }
+
+ ++active_transaction_number;
+ active_transactions[counter] = active_transaction_number;
+ ++counter;
+
+ return active_transaction_number;
+ }
+
+ void delete_lock(QueueLock *val)
+ {
+ int i = 0;
+ int j = 0;
+
+ for(i = 0;i < lock_counter;i++)
+ {
+ if (lock_val_array[i] == val)
+ {
+ lock_val_array[i] = NULL;
+ for (j = i;j < lock_counter;j++)
+ {
+ lock_val_array[j] = lock_val_array[j + 1];
+ }
+
+ --lock_counter;
+ break;
+ }
+
+ }
+
+ }
+
+ int add_mem_location(ConcertedDef *mem)
+ {
+ if (memory_counter == 10)
+ {
+ cout<<"new memory location val cannot be added due to lack of element in array"<<endl;
+ throw -1;
+ }
+
+ mem_allocated_val_array[memory_counter] = mem;
+ ++memory_counter;
+
+ return 1;
+ }
+
+ void delete_mem_location(ConcertedDef *val)
+ {
+ int i = 0;
+ int j = 0;
+
+ for (i = 0; i < memory_counter;i++)
+ {
+ if (mem_allocated_val_array[i] != NULL)
+ {
+ if (mem_allocated_val_array[i] == val)
+ {
+ mem_allocated_val_array[i] = NULL;
+ for (j = i;j < memory_counter;j++)
+ {
+ mem_allocated_val_array[j] = mem_allocated_val_array[j + 1];
+ }
+
+ --memory_counter;
+ break;
+ }
+
+ }
+
+ }
+
+ }
+
+ void delete_transaction(int val)
+ {
+ int i = 0;
+ int j = 0;
+
+ for (i = 0;i < 10;i++)
+ {
+ if (active_transactions[i] == val)
+ {
+ active_transactions[i] = 0;
+ for (j = i;j < counter;j++)
+ {
+ active_transactions[j] = active_transactions[j + 1];
+ }
+
+ --counter;
+ }
+
+ }
+
+ }
+
+ void add_commit_val(ConcertedDef *val, ConcertedDef *copy_val1)
+ {
+
+ if (commit_val_counter == 10)
+ {
+ cout<<"commit val cannot be added due to lack of element in array"<<endl;
+ throw -1;
+ }
+
+ current_val[commit_val_counter] = val;
+ copy_val[commit_val_counter] = copy_val1;
+ ++commit_val_counter;
+ }
+
+ void add_lock(QueueLock *val)
+ {
+
+ if (lock_counter == 10)
+ {
+ cout<<"lock cannot be added due to lack of element in array"<<endl;
+ throw -1;
+ }
+
+ lock_val_array[lock_counter] = val;
+ ++lock_counter;
+ }
+
+ void commit_transaction()
+ {
+ int i = 0;
+
+ delete_val = 0;
+ for (i = 0;i < commit_val_counter;i++)
+ {
+ (current_val[i])->copy_pointer_val(copy_val[i]);
+ }
+
+ cout<<"commit"<<endl;
+
+ }
+
+ ~TransactionManager()
+ {
+ int i = 0;
+
+ if (delete_val == 1)
+ {
+ cout<<"Rollback"<<endl;
+ for (i = 0;i < lock_counter;i++)
+ {
+ if (lock_val_array[i] != NULL && (lock_val_array[i])->CheckLockIsAcquired())
+ {
+ lock_val_array[i]->ReleaseLock();
+ }
+
+ }
+
+ i = 0;
+
+ for (i = 0;i < memory_counter;i++)
+ {
+ if (mem_allocated_val_array[i] != NULL)
+ {
+ free(mem_allocated_val_array[i]);
+ }
+
+ }
+
+ delete_transaction(current_transaction_number);
+
+ }
+
+ }
+};
+
+int TransactionManager::counter = 0;
+int TransactionManager::active_transaction_number = 0;
+int TransactionManager::active_transactions[10] = {0,0,0,0,0,0,0,0,0,0};
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/makefile
----------------------------------------------------------------------
diff --git a/makefile b/makefile
index db60c8e..adfb34a 100644
--- a/makefile
+++ b/makefile
@@ -9,25 +9,25 @@ mkdirectory :
libconcerted.a : $(OBJS)
ar cr build/libconcerted.a $(OBJS)
-obj/CacheManager.o : src/CacheManager.h
+obj/CacheManager.o : include/CacheManager.h
g++ -c $< -o $@
-obj/ConcDCT.o : src/ConcDCT.h
+obj/ConcDCT.o : include/ConcDCT.h
g++ -c $< -o $@
-obj/ConcInvertedIndex.o : src/ConcInvertedIndex.h
+obj/ConcInvertedIndex.o : include/ConcInvertedIndex.h
g++ -c $< -o $@
-obj/ConcMAT.o : src/ConcMAT.h
+obj/ConcMAT.o : include/ConcMAT.h
g++ -c $< -o $@
-obj/ConcQueue.o : src/ConcQueue.h
+obj/ConcQueue.o : include/ConcQueue.h
g++ -c $< -o $@
-obj/ConcSegHashTable.o : src/ConcSegHashTable.h
+obj/ConcSegHashTable.o : include/ConcSegHashTable.h
g++ -c $< -o $@
clean:
rm build/libconcerted.a
rm -r obj
- rm -r build
\ No newline at end of file
+ rm -r build
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/src/CacheManager.h
----------------------------------------------------------------------
diff --git a/src/CacheManager.h b/src/CacheManager.h
deleted file mode 100644
index 4c137f3..0000000
--- a/src/CacheManager.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#include <iostream>
-#include "ConcDef.h"
-using namespace std;
-
-class CacheManager
-{
- ConcertedDef *val_array[10];
- int current_counter;
-public:
- CacheManager()
- {
- int i = 0;
-
- for (i = 0;i < 10;i++)
- {
- val_array[i] = NULL;
- }
-
- current_counter = 0;
- }
-
- virtual ConcertedDef* search_val(...);
-
- void add_val(ConcertedDef *val)
- {
- if (current_counter < 10)
- {
- val_array[current_counter] = val;
- ++current_counter;
-
- return;
- }
-
- val_array[0] = val;
- }
-};
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/src/ConcDCT.h
----------------------------------------------------------------------
diff --git a/src/ConcDCT.h b/src/ConcDCT.h
deleted file mode 100644
index 59a4e34..0000000
--- a/src/ConcDCT.h
+++ /dev/null
@@ -1,348 +0,0 @@
-#include <iostream>
-#include "TransactionManager.h"
-using namespace std;
-
-class dct_node:public ConcertedDef
-{
- int value;
- int level;
- int current_insertion_index;
- dct_node *child_pointer;
- dct_node *next;
- QueueLock *read_lock_val;
- QueueLock *write_lock_val;
-public:
- dct_node()
- {
- value = 0;
- level = 0;
- current_insertion_index = 0;
- child_pointer = NULL;
- next = NULL;
- read_lock_val = new QueueLock;
- write_lock_val = new QueueLock;
- }
-
- void copy_pointer_val(ConcertedDef *copy_val1)
- {
- dct_node *copy_val = (dct_node*)copy_val1;
- *this = *copy_val;
- }
-
- int getval()
- {
- return value;
- }
-
- void setval(int a)
- {
- value = a;
- }
-
- int getlevel()
- {
- return level;
- }
-
- void setlevel(int a)
- {
- level = a;
- }
-
- void insert(dct_node *pointer_val)
- {
- dct_node *traverse = NULL;
-
- if (child_pointer == NULL)
- {
- child_pointer = pointer_val;
- return;
- }
-
- traverse = child_pointer;
-
- while ((traverse->getnext()) != NULL)
- {
- traverse = traverse->getnext();
- }
-
- traverse->setnext(pointer_val);
-
- }
-
- dct_node* get_child_pointer()
- {
- return child_pointer;
- }
-
- void setnext(dct_node *next_element_pointer)
- {
- next = next_element_pointer;
- }
-
- dct_node* getnext()
- {
- return next;
- }
-
- QueueLock* getread_lock_val()
- {
- return read_lock_val;
- }
-
- QueueLock* getwrite_lock_val()
- {
- return write_lock_val;
- }
-
- ~dct_node()
- {
- dct_node *traverse = child_pointer;
- dct_node *temp = NULL;
-
- if (child_pointer != NULL)
- {
- temp = child_pointer->getnext();
- }
-
- while (traverse != NULL)
- {
- if (child_pointer != NULL)
- {
- delete child_pointer;
- }
-
- traverse = temp;
- if (traverse != NULL)
- {
- temp = traverse->getnext();
- }
-
- }
-
- }
-};
-
-class dct_tree
-{
- dct_node *dummy;
- int number_of_nodes;
-public:
- dct_tree(int n)
- {
- dummy = new dct_node;
- dummy->setlevel(0);
- number_of_nodes = n;
- }
-
- dct_tree(dct_node *val, int n)
- {
- dummy = val;
- dummy->setlevel(0);
- number_of_nodes = n;
- }
-
- dct_node* getdummy()
- {
- return dummy;
- }
-
- int getnumber_of_nodes()
- {
- return number_of_nodes;
- }
-
- ~dct_tree()
- {
- delete dummy;
- }
-
-};
-
- dct_node* search_val(int[3], dct_node*);
- dct_node* search_node(int, dct_node*);
- dct_node* insert_val(int[3], dct_node*);
- dct_tree* build_dcttree();
-
- dct_tree* build_dcttree(int n)
- {
- dct_tree *tree_val = NULL;
-
- tree_val = new dct_tree(n);
-
- return tree_val;
- }
-
- dct_node* search_node(int val, dct_node *parent_pointer, int locksTaken)
- {
- dct_node *head = NULL;
- dct_node *traverse = NULL;
- QueueLock *write_lock_val = parent_pointer->getwrite_lock_val();
- QueueLock *read_lock_val = parent_pointer->getread_lock_val();
-
- if (locksTaken == 0)
- {
- while ((write_lock_val->CheckLockIsAcquired()) == 1)
- {
- cout<<"Waiting for write lock release1"<<endl;
- }
-
- }
-
- if (locksTaken == 0)
- {
- read_lock_val->GetLock();
- }
-
- if (parent_pointer == NULL)
- {
- return NULL;
- }
-
- head = parent_pointer->get_child_pointer();
- if (locksTaken == 0)
- {
- read_lock_val->ReleaseLock();
- }
-
- traverse = head;
-
- while (traverse != NULL)
- {
- write_lock_val = traverse->getwrite_lock_val();
- read_lock_val = traverse->getread_lock_val();
-
- while ((write_lock_val->CheckLockIsAcquired()) == 1)
- {
- }
-
- if (locksTaken == 0)
- {
- read_lock_val->GetLock();
- }
-
- if ((traverse->getval()) == val)
- {
- cout<<"value found search"<<" "<<traverse->getval()<<" "<<val<<endl;
- return traverse;
- }
-
- if (locksTaken == 0)
- {
- read_lock_val->ReleaseLock();
- }
-
- traverse = traverse->getnext();
- }
-
- cout<<"value not found"<<endl;
- return NULL;
- }
-
- dct_node* search_val(int search_val_array[3], dct_tree *tree_val)
- {
- dct_node *dummy = tree_val->getdummy();
- dct_node *traverse = dummy;
- dct_node *temp = NULL;
- int i = 0;
- int current_value = 0;
-
- for (i = 0;i < (tree_val->getnumber_of_nodes());i++)
- {
- current_value = search_val_array[i];
- temp = search_node(current_value, traverse,1);
- if (temp == NULL)
- {
- cout<<"value not found search val"<<" "<<current_value<<endl;
- return NULL;
- }
-
- traverse = temp;
- }
-
- return traverse;
-
- }
-
- dct_tree* copy_val(dct_node *val, int number_of_nodes)
- {
- int i = 0;
- dct_node *traverse1 = new dct_node();
- dct_node *traverse2 = val->get_child_pointer();
- dct_node *temp = NULL;
- dct_tree *return_val = NULL;
-
- i = val->getlevel();
-
- traverse1->setval(val->getval());
- traverse1->setlevel(val->getlevel());
- for (;i < number_of_nodes;i++)
- {
- while (traverse2 != NULL)
- {
- temp = new dct_node(*(traverse2));
- traverse1->insert(temp);
- copy_val(temp, number_of_nodes);
- traverse2 = traverse2->getnext();
- }
-
- }
-
- return_val = new dct_tree(traverse1, number_of_nodes);
-
- return return_val;
-
- }
-
- dct_node* insert_val(int val_array[3], dct_tree *tree_val, TransactionManager &transact_val1)
- {
- dct_tree *val1 = copy_val((tree_val->getdummy()), (tree_val->getnumber_of_nodes()));
- dct_node *dummy = val1->getdummy();
- dct_node *dummy2 = tree_val->getdummy();
- dct_node *traverse = NULL;
- dct_node *temp = NULL;
- dct_node *temp_return = NULL;
- QueueLock *write_lock_val = dummy->getwrite_lock_val();
- QueueLock *read_lock_val = dummy->getread_lock_val();
- int i = 0;
-
- traverse = dummy;
- transact_val1.add_commit_val(dummy2, dummy);
- for (i = 0;i < (tree_val->getnumber_of_nodes());i++)
- {
- write_lock_val = traverse->getwrite_lock_val();
- read_lock_val = traverse->getread_lock_val();
- transact_val1.add_lock(write_lock_val);
-
- while ((read_lock_val->CheckLockIsAcquired()) == 1)
- {
- }
-
- if (!(write_lock_val->GetLock()))
- {
- cout<<"write lock not taken"<<endl;
- throw -1;
- }
-
- temp_return = search_node(val_array[i], traverse,1);
- if (temp_return == NULL)
- {
- temp = new dct_node;
- temp->setval(val_array[i]);
- temp->setlevel(i);
- traverse->insert(temp);
- write_lock_val->ReleaseLock();
- transact_val1.delete_lock(write_lock_val);
- traverse = temp;
- }
- else
- {
- write_lock_val->ReleaseLock();
- transact_val1.delete_lock(write_lock_val);
-
- traverse = temp_return;
- }
-
- }
-
- }
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/src/ConcDef.h
----------------------------------------------------------------------
diff --git a/src/ConcDef.h b/src/ConcDef.h
deleted file mode 100644
index c518e6c..0000000
--- a/src/ConcDef.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <iostream>
-using namespace std;
-
-class ConcertedDef
-{
-public:
- virtual void copy_pointer_val(ConcertedDef *copy_val1)
- {
- cout<<"in ConcertedDef copy_pointer_val"<<endl;
- }
-};
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/src/ConcInvertedIndex.h
----------------------------------------------------------------------
diff --git a/src/ConcInvertedIndex.h b/src/ConcInvertedIndex.h
deleted file mode 100644
index 9fbab2f..0000000
--- a/src/ConcInvertedIndex.h
+++ /dev/null
@@ -1,301 +0,0 @@
-#include<iostream>
-using namespace std;
-
-template<int n, int index> class inv_index_node
-{
- int key;
- int values_array[10][n-1];
- inv_index_node<n, index> *next;
- int number_of_attributes;
- int index_location;
-public:
- inv_index_node()
- {
- int i = 0;
- int j = 0;
-
- key = 0;
-
- for(i = 0;i < n;i++)
- {
- for(j = 0;j < 10;j++)
- {
- values_array[i][j] = 0;
- }
-
- }
-
- number_of_attributes = n - 1;
- index_location = index;
- next = NULL;
- }
-
- void setkey(int val)
- {
- key = val;
- }
-
- int getkey()
- {
- return key;
- }
-
- void setval(int val, int row, int column)
- {
- values_array[row][column] = val;
- }
-
- int getval(int row, int column)
- {
- return values_array[row][column];
- }
-
- void setnext(inv_index_node<n, index> *val)
- {
- next = val;
- }
-
- inv_index_node<n, index>* getnext()
- {
- return next;
- }
-
- const int getnumber_of_attributes()
- {
- return number_of_attributes;
- }
-
- const int getindex_location()
- {
- return index_location;
- }
-};
-
- template<int n, int index> class inv_index
- {
- inv_index_node<n,index> *dummy;
- public:
- inv_index()
- {
- dummy = NULL;
- }
-
- inv_index_node<n,index>* get_dummy()
- {
- return dummy;
- }
-
- void insert_val(inv_index_node<n,index> *val)
- {
- inv_index_node<n, index> *traverse = dummy;
-
- if (dummy == NULL)
- {
- dummy = val;
- return;
- }
-
- while ((dummy->getnext()) != NULL)
- {
- dummy = dummy->getnext();
- }
-
- dummy->setnext(val);
- }
-
- };
-
-
-
- template<int n, int index> int search_val(int *att_values, inv_index<n,index> *index_val)
- {
- int i = 0;
- inv_index_node<n,index> *traverse = index_val->get_dummy();
- int number_of_attributes = traverse->getnumber_of_attributes();
- int index_search = *(att_values + traverse->getindex_location());
- int return_val;
- inv_index_node<n,index> *temp = NULL;
-
- return_val = 0;
-
- temp = search_list(index_search, index_val);
-
- if (temp == NULL)
- {
- cout<<"value not found1"<<" "<<index_search<<endl;
- return -1;
- }
-
- for (i = 1;i < n;i++)
- {
- if (i != index)
- {
- return_val = search_array_val(*(att_values + i), temp, i);
- //return_val = search_array(&(att_values[1]), (inv_index->get_dummy()));
-
- if (return_val == -1)
- {
- cout<<"value not found"<<" "<<*(att_values + i)<<" "<<i<<" "<<index<<endl;
- return -1;
- }
-
- }
-
- }
-
- return 1;
- }
-
- template<int n, int index> inv_index_node<n, index>* search_list(int val, inv_index<n,index> *index_val)
- {
- inv_index_node<n,index> *traverse = index_val->get_dummy();
-
- while (traverse != NULL && traverse->getkey() != val)
- {
- traverse = traverse->getnext();
- }
-
- if (traverse == NULL)
- {
- return NULL;
- }
-
- return traverse;
- }
-
- template<int n, int index> int search_array(int *val_array, inv_index_node<n,index> *index_node_val)
- {
- int i;
- int j;
- int found;
-
- i = 0;
- j = 0;
- found = 0;
-
- for (i = 0; i < (n - 1);i++)
- {
- for (j = 0;j < 10;j++)
- {
- if (*(val_array + i) == (index_node_val->getval(i,j)))
- {
- cout<<"value found"<<" "<<*(val_array + i)<<" "<<i<<" "<<j<<endl;
- ++found;
- break;
- }
- else
- {
- cout<<"value not found"<<" "<<*(val_array + i)<<" "<<i<<" "<<j<<endl;
- }
- }
- }
-
- if (found == (n - 1))
- {
- cout<<"values found"<<" "<<found<<endl;
- return 1;
- }
-
- cout<<"values not found"<<" "<<found<<endl;
- return -1;
- }
-
- template<int n, int index> int search_array_val(int val, inv_index_node<n, index> *index_node_val, int index_location)
- {
- int i = 0;
-
- cout<<"index location value is"<<" "<<val<<" "<<index_location<<endl;
- for (i = 0;i < 10;i++)
- {
- if (i != index)
- {
- if ((index_node_val->getval((index_location - 2), i)) == val)
- {
- cout<<"value found2"<<" "<<val<<" "<<i<<endl;
- return i;
- }
- else
- {
- cout<<"value not found4"<<" "<<val<<" "<<index_node_val->getval((index_location - 2), i)<<" "<<index_location<<endl;
- }
-
- }
-
- }
-
- cout<<"value not found2"<<" "<<val<<" "<<(index_location - 2)<<endl;
- return -1;
- }
-
- template<int n, int index> int insert_val_array(int val, inv_index<n, index> *index_val, int index_location)
- {
- int i = 0;
- int j = 0;
- int flag_found = 0;
- inv_index_node<n,index> *traverse = index_val->get_dummy();
-
- cout<<"index_location is"<<" "<<val<<" "<<index_location<<endl;
- for (j = 0;j < 10;j++)
- {
- if ((traverse->getval((index_location - 1), j)) == 0)
- {
- cout<<"empty space found"<<" "<<(index_location - 1)<<" "<<j<<endl;
- flag_found = 1;
- break;
- }
-
- }
-
- if (flag_found == 1)
- {
- traverse->setval(val, (index_location - 1), j);
- cout<<"value inserted"<<" "<<val<<" "<<(index_location - 1)<<" "<<j<<endl;
- return 1;
- }
-
- return -1;
- }
-
- template<int n,int index> void insert_val(int att_values[], inv_index<n, index> *index_val)
- {
- int i = 0;
- int return_val = 0;
- int return_val_2 = 0;
- inv_index_node<n,index> *traverse = NULL;
- inv_index_node<n,index> *temp = NULL;
-
- traverse = search_list(*(att_values + index), index_val);
-
- if (traverse == NULL)
- {
- temp = new inv_index_node<n,index>;
- temp->setkey(*(att_values + index));
- index_val->insert_val(temp);
- traverse = temp;
- }
-
- for (i = 1;i < n;i++)
- {
- if (i != index)
- {
- return_val = search_array_val(*(att_values + i), (index_val->get_dummy()), i);
-
- if (return_val == -1)
- {
- return_val_2 = insert_val_array(*(att_values + i), index_val, i);
-
- if (return_val_2 == -1)
- {
- cout<<"value not inserted due to lack of space"<<endl;
- return;
- }
-
- return_val = 0;
- return_val_2 = 0;
- }
-
- }
-
- }
-
- }
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/src/ConcMAT.h
----------------------------------------------------------------------
diff --git a/src/ConcMAT.h b/src/ConcMAT.h
deleted file mode 100644
index 1c8dc0e..0000000
--- a/src/ConcMAT.h
+++ /dev/null
@@ -1,193 +0,0 @@
-#include<iostream>
-using namespace std;
-
-class mat_node
-{
- int value;
- int level;
- int current_insertion_index;
- mat_node *child_pointer_array[10];
-public:
- mat_node()
- {
- int i = 0;
- value = 0;
- level = 0;
- current_insertion_index = 0;
- for (i = 0;i < 10;i++)
- {
- *(child_pointer_array + i) = NULL;
- }
- }
- int getval()
- {
- return value;
- }
-
- void setval(int a)
- {
- value = a;
- }
-
- int getlevel()
- {
- return level;
- }
-
- void setlevel(int a)
- {
- level = a;
- }
-
- void insert(mat_node *pointer_val)
- {
- child_pointer_array[0] = pointer_val;
- }
-
- mat_node** get_child_pointer_array()
- {
- return child_pointer_array;
- }
-
- ~mat_node()
- {
- mat_node *traverse = child_pointer_array[0];
- int i = 0;
-
- while(traverse != NULL && i < 10)
- {
- delete traverse;
- ++i;
- traverse = *(child_pointer_array + i);
- }
-
- delete traverse;
-
- }
-};
-
- class mat_tree
- {
- mat_node *dummy;
- int number_of_attributes;
- public:
- mat_tree(int n)
- {
- dummy = new mat_node;
- dummy->setlevel(0);
- number_of_attributes = n;
- }
-
- mat_node* getdummy()
- {
- return dummy;
- }
-
- int getnumber_of_attributes()
- {
- return number_of_attributes;
- }
-
- ~mat_tree()
- {
- delete dummy;
- }
- };
-
- mat_tree* build_mattree(int);
- mat_node* search_node(int, mat_node*, mat_node*);
- mat_node* search_val(int[3],mat_node*);
- mat_node* insert_val(int[3],mat_node*);
-
- mat_tree* build_mattree(int n)
- {
- mat_tree* tree_val = NULL;
-
- tree_val = new mat_tree(n);
-
- return tree_val;
- }
-
- mat_node* search_node(int val, mat_node *parent_pointer, mat_node *dummy)
- {
- mat_node **traverse = parent_pointer->get_child_pointer_array();
- mat_node *temp = NULL;
- int i = 0;
-
- if (parent_pointer == NULL)
- {
- cout<<"parent pointer is NULL"<<endl;
- return NULL;
- }
-
- while (i < 3)
- {
- temp = *(traverse + i);
- if (temp != NULL)
- {
- if ((temp->getval()) == val)
- {
- cout<<"value found"<<" "<<temp->getval()<<" "<<val<<endl;
- return temp;
- }
-
- }
-
- ++i;
- }
-
- cout<<"value not found"<<endl;
- return NULL;
- }
-
- mat_node* search_val(int search_val_array[3], mat_tree *tree_val)
- {
- mat_node *dummy = tree_val->getdummy();
- mat_node *traverse = dummy;
- mat_node *temp = NULL;
- int i = 0;
- int current_value = 0;
-
- for (i = 0;i < 3;i++)
- {
- current_value = search_val_array[i];
- temp = search_node(current_value, traverse, dummy);
- if (temp == NULL)
- {
- cout<<"value not found"<<" "<<current_value<<endl;
- return NULL;
- }
-
- traverse = temp;
- }
-
- }
-
- mat_node* insert_val(int val_array[3], mat_tree *tree_val)
- {
- mat_node *dummy = tree_val->getdummy();
- mat_node *traverse = NULL;
- mat_node *temp = NULL;
- mat_node *temp_return = NULL;
- int i = 0;
-
- traverse = dummy;
- for (i = 0;i < 3;i++)
- {
- temp_return = search_node(val_array[i], traverse, dummy);
- if (temp_return == NULL)
- {
- temp = new mat_node;
- temp->setval(val_array[i]);
- temp->setlevel(i);
- traverse->insert(temp);
- traverse = temp;
- }
- else
- {
- traverse = temp_return;
- }
-
- }
-
- }
http://git-wip-us.apache.org/repos/asf/incubator-concerted/blob/fa6ba986/src/ConcQueue.h
----------------------------------------------------------------------
diff --git a/src/ConcQueue.h b/src/ConcQueue.h
deleted file mode 100644
index 07dba00..0000000
--- a/src/ConcQueue.h
+++ /dev/null
@@ -1,239 +0,0 @@
-#ifndef CONCQUEUE_INCLUDED
-#define CONCQUEUE_INCLUDED
-
-#include<iostream>
-#include<stdlib.h>
-using namespace std;
-
-typedef struct {
-
- volatile int lock_value;
-
-} lock_queue;
-
-template<class data_val_type> class QueueElement
-{
- data_val_type data_value;
- QueueElement *next;
-public:
- QueueElement(data_val_type a):data_value(a),next(NULL)
- {
- }
-
- data_val_type GetData() const
- {
- return data_value;
- }
-
- void SetData(data_val_type val)
- {
- data_value = val;
- }
-
- void SetPointer(QueueElement *a)
- {
- next = a;
- }
-
- QueueElement* GetPointer() const
- {
- return next;
- }
-
- const data_val_type* GetPointerToData() const
- {
- return (&data_value);
- }
-};
-
-template<class data_val_type> class ConcQueue
-{
- QueueElement<data_val_type> *head;
- QueueElement<data_val_type> *tail;
- lock_queue insertion_lock;
- lock_queue deletion_lock;
-public:
- ConcQueue():head(NULL),tail(NULL)
- {
- insertion_lock.lock_value = 0;
- deletion_lock.lock_value = 0;
- }
-
- int CAS(volatile int *val, int compare_value, int swap_value)
- {
-
- return __sync_bool_compare_and_swap(val, compare_value, swap_value);
- }
-
- void PrintQueue()
- {
- const QueueElement<data_val_type> *traverse = NULL;
-
- traverse = head;
-
- while(traverse != NULL)
- {
- cout<<traverse->GetData()<<endl;
- traverse = traverse->GetPointer();
- }
- }
-
- const QueueElement<data_val_type>* AddElement(data_val_type val)
- {
- QueueElement<data_val_type> *temp = NULL;
- lock_queue current_lock;
-
- temp = new QueueElement<data_val_type>(val);
- temp->SetPointer(NULL);
-
- /* Synchronization by locking with compare and swap.The current value of
- * lock is compared with the expected value(locked,unlocked) and
- * swapped accordingly.Threads spin until they acquire the lock.
- */
- while(!(CAS(&(insertion_lock.lock_value), 0, 1)))
- {
- // Spinning waiting for lock.
- }
-
- if(head == NULL && tail == NULL)
- {
- tail = new QueueElement<data_val_type>(val);
- head = tail;
- CAS(&(insertion_lock.lock_value), 1 ,0);
-
- return (head);
- }
- else
- {
- tail->SetPointer(temp);
- tail = temp;
- CAS(&(insertion_lock.lock_value), 1, 0);
-
- return (temp);
- }
- }
-
- const QueueElement<data_val_type>* AddElementInFront(data_val_type val) //Use with EXTREME caution.
- {
- QueueElement<data_val_type> *temp = NULL;
- lock_queue current_lock;
-
- temp = new QueueElement<data_val_type>(val);
- temp->SetPointer(NULL);
-
- /* Synchronization by locking with compare and swap.The current value of
- * lock is compared with the expected value(locked,unlocked) and
- * swapped accordingly.Threads spin until they acquire the lock.
- */
- while(!(CAS(&(insertion_lock.lock_value), 0, 1)))
- {
- // Spinning waiting for lock.
- }
-
- if(head == NULL && tail == NULL)
- {
- tail = new QueueElement<data_val_type>(val);
- head = tail;
- CAS(&(insertion_lock.lock_value), 1 ,0);
-
- return (head);
- }
- else
- {
- temp->SetPointer(head);
- head = temp;
- }
-
- return (temp);
- }
- QueueElement<data_val_type>* GetElement()
- {
- QueueElement<data_val_type> *current_element = head;
- QueueElement<data_val_type> *temp = NULL;
-
- while(!(CAS(&(deletion_lock.lock_value), 0, 1)))
- {
- //Spin waiting for the lock
- }
-
- if(head != NULL)
- {
- head = head->GetPointer();
- }
-
- CAS(&(deletion_lock.lock_value) ,1, 0);
- /* When popping an element from the queue and returning it,the
- * ownership of the element is changed from the queue to the
- * calling function. Hence, the element is no longer required
- * to be const.
- */
- //temp = const_cast<QueueElement<data_val_type>*> (current_element);
- temp = current_element;
- return (temp);
- }
-
- QueueElement<data_val_type>* SearchQueue(data_val_type val)
- {
- QueueElement<data_val_type> *traverse = head;
-
- while (traverse != NULL)
- {
- if ((traverse->GetData()) == val)
- {
- return (traverse);
- }
-
- traverse = traverse->GetPointer();
-
- }
-
- cout<<"value not found SearchQueue"<<endl;
-
- return NULL;
- }
-
- int GetToFront(QueueElement<data_val_type> val)
- {
- int val_found = 0;
- QueueElement<data_val_type> *traverse = head;
- QueueElement<data_val_type> *traverse2 = head;
-
- while (traverse != NULL)
- {
- if ((traverse->GetData()) == val)
- {
- cout<<"value found GetToFront"<<endl;
- val_found = 1;
- break;
- }
-
- traverse2 = traverse;
- traverse = traverse->GetPointer();
-
- }
-
- if (val_found == 1)
- {
- traverse2->SetPointer(traverse->GetPointer());
- AddElementInFront(traverse->GetData());
- return 1;
- }
-
- return -1;
- }
-
- ~ConcQueue()
- {
- QueueElement<data_val_type>* temp = head;
-
- while(head != NULL)
- {
- temp = head->GetPointer();
- delete head;
- head = temp;
- }
-
- }
-};
-
-#endif