MKDIR_P = mkdir -p
OBJ_DIR = bin
-CPP_SOURCES := constraint.cc inc_solver.cc
+CPP_SOURCES := constraint.cc inc_solver.cc set.cc
OBJECTS := $(CPP_SOURCES:%.cc=$(OBJ_DIR)/%.o) $(C_SOURCES:%.c=$(OBJ_DIR)/%.o)
--- /dev/null
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+#include "set.h"
+#include <stddef.h>
+#include <cassert>
+
+Node::Node(uint64 val, Node* r, Node* l){
+ range=false;
+ beginOrVal=val;
+ left = l;
+ right=r;
+}
+
+Node::Node(uint64 val):Node(val, NULL, NULL){}
+
+Node::Node(uint64 begin, uint64 end, Node* r, Node* l){
+ range=true;
+ beginOrVal=begin;
+ this->end= end;
+ right=r;
+ left=l;
+}
+
+Node::Node(uint64 begin, uint64 end):Node(begin, end, NULL, NULL){}
+
+Comparison Node::compare(uint64 val){
+ if(range){
+ if(val> end)
+ return GREATER;
+ else if(val < beginOrVal)
+ return LESS;
+ else
+ return EQUAL;
+ }else{
+ if(val> beginOrVal)
+ return GREATER;
+ else if(val< beginOrVal)
+ return LESS;
+ else
+ return EQUAL;
+ }
+}
+
+void Node::addNode(Node* n){
+ assert(!n->isRange());
+ Comparison comp = compare(n->getBeginOrRange());
+ if(comp == GREATER){
+ if(right!=NULL)
+ right->addNode(n);
+ else
+ right=n;
+ }else if(comp == LESS){
+ if(left!= NULL)
+ left->addNode(n);
+ else
+ left = n;
+ }
+
+}
+
+Set::Set(Type t, uint64* elements, int num){
+ type=t;
+ size=num;
+ for(int i=0; i<num; i++){
+ addItem(elements[i]);
+ }
+}
+
+Set::Set(Type t, uint64 lowrange, uint64 highrange){
+ assert(highrange>lowrange);
+ type =t;
+ size = highrange-lowrange+1;
+ root = new Node(lowrange,highrange);
+}
+
+Set::Set(Type t): type(t),
+ size(0),
+ root(NULL)
+{
+}
+
+void Set::addItem(uint64 element){
+ Node* n = new Node(element);
+ if(root==NULL)
+ root=n;
+ else
+ root->addNode(n);
+}
+
+
\ No newline at end of file
--- /dev/null
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/*
+ * File: set.h
+ * Author: hamed
+ *
+ * Created on June 13, 2017, 3:01 PM
+ */
+
+#ifndef SET_H
+#define SET_H
+
+#include "types.h"
+
+enum Comparison{LESS, EQUAL, GREATER};
+
+class Node{
+private:
+ bool range;
+ // If it isn't a range, begin contains the actual value of the element
+ uint64 beginOrVal;
+ uint64 end;
+ Node* right;
+ Node* left;
+public:
+ Node(uint64 val, Node* r, Node* l);
+ Node(uint64 val);
+ Node(uint64 begin, uint64 end, Node* r, Node* l);
+ Node(uint64 begin, uint64 end);
+ bool isRange(){return range;}
+ uint64 getBeginOrRange(){return beginOrVal;}
+ Comparison compare(uint64 val);
+ /**
+ * Searches the tree, if new node exists in the tree ( whether its value
+ * is in range of another node, or there is another node with the value of
+ * node n) this function just returns!
+ * @param n
+ */
+ void addNode(Node* n);
+};
+// For now, we can consider it as a simple binary tree, but we can have fancier
+// trees for future
+class Set{
+ Type type;
+ uint64 size;
+ Node* root;
+ Set(Type t, uint64 * elements, int num);
+ Set(Type t, uint64 lowrange, uint64 highrange);
+ Set(Type t);
+ /**
+ * For know all sets are considered to be mutable, we can change it later on
+ * if it was necessary.
+ * @param set
+ * @param element
+ */
+ void addItem(uint64 element);
+ ELEMENT* createUniqueItem(Set * set);
+
+};
+
+
+#endif /* SET_H */
+
--- /dev/null
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/*
+ * File: Type.h
+ * Author: hamed
+ *
+ * Created on June 13, 2017, 1:33 PM
+ */
+
+#ifndef TYPE_H
+#define TYPE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef unsigned long int uint64;
+typedef uint64 Type;
+
+struct Element{
+ uint64 value;
+};
+
+typedef struct Element ELEMENT;
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TYPE_H */
+