#include "tableentry.h"
#include "ordernode.h"
#include "orderedge.h"
+#include "ordergraph.h"
VectorImpl(Table, Table *, 4);
VectorImpl(Set, Set *, 4);
VectorImpl(TableEntry, TableEntry *, 4);
VectorImpl(ASTNode, ASTNode *, 4);
VectorImpl(Int, uint64_t, 4);
+VectorImpl(OrderNode, OrderNode*, 4);
+VectorImpl(OrderGraph, OrderGraph*, 4);
inline unsigned int Ptr_hash_function(void * hash) {
return (unsigned int)((int64)hash >> 4);
return key1->sink == key2->sink && key1->source == key2->source && key1->order == key2->order;
}
+static inline unsigned int node_info_hash_function(OrderNode * hash) {
+ return (uint)((int64)hash >> 4);
+}
+
+static inline bool node_info_equals(OrderNode * key1, OrderNode * key2) {
+ return key1 == key2;
+}
+
HashTableImpl(OrderPair, OrderPair *, OrderPair *, order_pair_hash_Function, order_pair_equals, ourfree);
+HashTableImpl(Node, OrderNode *, NodeInfo *, node_info_hash_function, node_info_equals, ourfree);
+
HashSetImpl(TableEntry, TableEntry*, table_entry_hash_Function, table_entry_equals);
HashSetImpl(OrderNode, OrderNode*, order_node_hash_Function, order_node_equals);
HashSetImpl(OrderEdge, OrderEdge*, order_edge_hash_Function, order_edge_equals);
-
VectorDef(TableEntry, TableEntry *);
VectorDef(ASTNode, ASTNode *);
VectorDef(Int, uint64_t);
+VectorDef(OrderNode, OrderNode*);
+VectorDef(OrderGraph, OrderGraph*);
HashTableDef(Void, void *, void *);
HashTableDef(OrderPair, OrderPair *, OrderPair *);
+HashTableDef(Node, OrderNode*, NodeInfo*);
HashSetDef(Void, void *);
HashSetDef(TableEntry, TableEntry*);
--- /dev/null
+
+#include "orderencoder.h"
+#include "structs.h"
+#include "csolver.h"
+#include "boolean.h"
+#include "ordergraph.h"
+#include "order.h"
+
+
+NodeInfo* allocNodeInfo(){
+ NodeInfo* This = (NodeInfo*) ourmalloc(sizeof(NodeInfo));
+ This->finishTime = 0;
+ This->status = NOTVISITED;
+ return This;
+}
+
+void deleteNodeInfo(NodeInfo* info){
+ ourfree(info);
+}
+
+OrderEncoder* allocOrderEncoder(){
+ OrderEncoder* This = (OrderEncoder*) ourmalloc(sizeof(OrderEncoder));
+ initDefVectorOrderGraph( &This->graphs );
+ return This;
+}
+
+void deleteOrderEncoder(OrderEncoder* This){
+ uint size = getSizeVectorOrderGraph(&This->graphs);
+ for(uint i=0; i<size; i++){
+ deleteOrderGraph(getVectorOrderGraph(&This->graphs, i));
+ }
+ ourfree(This);
+}
+
+OrderEncoder* buildOrderGraphs(CSolver* This){
+ uint size = getSizeVectorOrder(This->allOrders);
+ OrderEncoder* oEncoder = allocOrderEncoder();
+ for(uint i=0; i<size; i++){
+ OrderGraph* orderGraph = allocOrderGraph();
+ Order* order = getVectorOrder(This->allOrders, i);
+ uint constrSize = getSizeVectorBoolean(&order->constraints);
+ for(uint j=0; j<constrSize; j++){
+ addOrderConstraintToOrderGraph(orderGraph, getVectorBoolean(&order->constraints, j));
+ }
+ pushVectorOrderGraph(&oEncoder->graphs, orderGraph);
+ }
+ return oEncoder;
+}
+
+void DFS(OrderGraph* graph, VectorOrderNode* finishNodes, HashTableNode* nodeToInfo, bool isReverse){
+ uint timer=0;
+ HSIteratorOrderNode* iterator = iteratorOrderNode(graph->nodes);
+ while(hasNextOrderNode(iterator)){
+ OrderNode* node = nextOrderNode(iterator);
+ NodeInfo* info= getNode(nodeToInfo, node);
+ if(info->status == NOTVISITED){
+ info->status = VISITED;
+ //TODO ...
+ }
+ }
+ deleteIterOrderNode(iterator);
+}
+
+void DFSNodeVisit(OrderNode* node, VectorOrderNode* finishNodes, HashTableNode* nodeToInfo, uint* timer, bool isReverse){
+ NodeInfo* info= getNode(nodeToInfo, node);
+}
+
+void initializeNodeInfoSCC(OrderGraph* graph, HashTableNode* nodeToInfo){
+ HSIteratorOrderNode* iterator = iteratorOrderNode(graph->nodes);
+ while(hasNextOrderNode(iterator)){
+ putNode(nodeToInfo, nextOrderNode(iterator), allocNodeInfo());
+ }
+ deleteIterOrderNode(iterator);
+}
+
+void computeStronglyConnectedComponentGraph(OrderGraph* graph){
+ VectorOrderNode finishNodes;
+ initDefVectorOrderNode(& finishNodes);
+ HashTableNode* nodeToInfo = allocHashTableNode(HT_INITIAL_CAPACITY, HT_DEFAULT_FACTOR);
+ initializeNodeInfoSCC(graph, nodeToInfo);
+ // TODO
+ deleteHashTableNode(nodeToInfo);
+}
+
+void orderAnalysis(CSolver* solver){
+ OrderEncoder* oEncoder = buildOrderGraphs(solver);
+ uint size = getSizeVectorOrderGraph(&oEncoder->graphs);
+ for(uint i=0; i<size; i++){
+ OrderGraph* graph = getVectorOrderGraph(&oEncoder->graphs, i);
+ computeStronglyConnectedComponentGraph(graph);
+ }
+}
+
--- /dev/null
+/*
+ * File: orderencoder.h
+ * Author: hamed
+ *
+ * Created on August 8, 2017, 6:36 PM
+ */
+
+#ifndef ORDERGRAPHBUILDER_H
+#define ORDERGRAPHBUILDER_H
+#include "classlist.h"
+#include "structs.h"
+#include "mymemory.h"
+
+enum NodeStatus {NOTVISITED, VISITED, FINISHED};
+typedef enum NodeStatus NodeStatus;
+
+struct NodeInfo{
+ NodeStatus status;
+ uint finishTime;
+};
+
+struct OrderEncoder{
+ VectorOrderGraph graphs;
+};
+
+NodeInfo* allocNodeInfo();
+void deleteNodeInfo(NodeInfo* info);
+OrderEncoder* allocOrderEncoder();
+void deleteOrderEncoder(OrderEncoder* This);
+
+OrderEncoder* buildOrderGraphs(CSolver* This);
+void computeStronglyConnectedComponentGraph(OrderGraph* graph);
+void orderAnalysis(CSolver* solver);
+void initializeNodeInfoSCC(OrderGraph* graph, HashTableNode* nodeToInfo);
+void DFSNodeVisit(OrderNode* node, VectorOrderNode* finishNodes, HashTableNode* nodeToInfo, uint* timer, bool isReverse);
+void DFS(OrderGraph* graph, VectorOrderNode* finishNodes, HashTableNode* nodeToInfo, bool isReverse);
+
+#endif /* ORDERGRAPHBUILDER_H */
+
OrderNode* from = getOrderNodeFromOrderGraph(graph, bOrder->first, bOrder->order);
OrderNode* to = getOrderNodeFromOrderGraph(graph, bOrder->second, bOrder->order);
addOrderEdge(graph, from, to, constr);
-
}
-
void deleteOrderGraph(OrderGraph* graph){
HSIteratorOrderNode* iterator = iteratorOrderNode(graph->nodes);
while(hasNextOrderNode(iterator)){
+++ /dev/null
-
-#include "ordergraphbuilder.h"
-#include "structs.h"
-#include "csolver.h"
-#include "boolean.h"
-#include "ordergraph.h"
-
-
-void buildOrderGraph(CSolver* This){
- uint size = getSizeVectorBoolean(This->constraints);
- OrderGraph* orderGraph = allocOrderGraph();
- for(uint i=0; i<size; i++){
- Boolean* constraint = getVectorBoolean(This->constraints, i);
- if(GETBOOLEANTYPE(constraint) == ORDERCONST){
- addOrderConstraintToOrderGraph(orderGraph, constraint);
- }
- }
- //TODO: We should add the orderGraph to our encoder
- deleteOrderGraph(orderGraph);
-}
-
+++ /dev/null
-/*
- * File: ordergraphbuilder.h
- * Author: hamed
- *
- * Created on August 8, 2017, 6:36 PM
- */
-
-#ifndef ORDERGRAPHBUILDER_H
-#define ORDERGRAPHBUILDER_H
-#include "classlist.h"
-
-void buildOrderGraph(CSolver* This);
-void computeStronglyConnectedComponentGraph(OrderGraph* graph);
-#endif /* ORDERGRAPHBUILDER_H */
-
struct OrderEdge;
typedef struct OrderEdge OrderEdge;
+struct OrderEncoder;
+typedef struct OrderEncoder OrderEncoder;
+
+struct NodeInfo;
+typedef struct NodeInfo NodeInfo;
+
typedef unsigned int uint;
typedef long int int64;
typedef uint64_t VarType;