-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubRow.h
129 lines (103 loc) · 4.4 KB
/
SubRow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#pragma once
#include "basic_types.h"
#include "swap_target.h"
#include "multithread.h"
#include <vector>
using namespace std;
void moveSubrowCellLL(size_t p_cell_pos, Coor p_pos);
bool testIfAlreadyCongested(size_t p_cell_pos, Coor p_pos);
bool canBeSwaped(size_t cell_index, SwapTarget target);
int findSubRow(Coor p_pos);
//clusters are not shared between threads, so clusters need no locks
class Cluster
{
public:
Cluster(): coordinate(0.0), lx(0.0), width(0.0), height(0.0) {}
Cluster(coor_type p_lx, coor_type p_coor): coordinate(p_coor), lx(p_lx), width(0.0), height(0.0) {}
Cluster(coor_type p_lx, coor_type p_coor, coor_type p_width, coor_type p_height): coordinate(p_coor), lx(p_lx),
width(p_width), height(p_height) {}
void setBoundary(Coor p_ll, coor_type p_width, coor_type p_height) {lx = p_ll.x; coordinate = p_ll.y; width = p_width; height = p_height;}
//void setCoor(Coor p_coor) {ll = p_coor;}
void set_lx(coor_type p_lx) {lx = p_lx;}
//void setWidth(coor_type p_width) {width = p_width;}
void setHeight(coor_type p_height) {height = p_height;}
void addCell(size_t p_cell, coor_type p_width)
{
width += p_width;
cell.push_back(p_cell);
} // addCell
coor_type get_lx() {return lx;}
coor_type get_rx() {return lx + width;}
coor_type getCoor() {return coordinate;}
coor_type getWidth() {return width;}
coor_type getHeight() {return height;}
size_t getCell(size_t p_pos) {return cell.at(p_pos);}
size_t getCellNum() {return cell.size();}
void deleteCell(size_t cell);
coor_type getCellCenter();
void swapCell(size_t p_pos_1, size_t p_pos_2) {swap(cell[p_pos_1], cell[p_pos_2]);}
void copy(Cluster& p_cluster, int p_begin, int p_end);
private:
coor_type lx;
coor_type coordinate;// Y-coor
coor_type width;
coor_type height;
vector<size_t> cell;
}; // Cluster
/* ************************************************** */
class SubRow
{
public:
SubRow(): coordinate(0.0), lx(0.0), width(0.0), height(0.0), used_width(0.0) {}
bool operator <(const SubRow& other) const{return lx < other.lx;} // for sorting
void setBoundary(Coor p_ll, coor_type p_width, coor_type p_height) {lx = p_ll.x; coordinate = p_ll.y; width = p_width; height = p_height;}
//void setCoor(coor_type p_coor) {coordinate = p_coor;}
void setWidth(coor_type p_width) {width = p_width;}
void setHeight(coor_type p_height) {height = p_height;}
void setCluster(Cluster p_cluster, size_t p_pos) {cluster.at(p_pos) = p_cluster;}
void addCluster(Cluster p_cluster) {cluster.push_back(p_cluster);}
coor_type get_lx() {return lx;}
coor_type get_rx() {return lx + width;}
coor_type getCoor() {return coordinate;}
coor_type getWidth() {return width;}
coor_type getHeight() {return height;}
//readers
//is lock needed? no lock yet
size_t getCell(size_t p_pos) {return cell.at(p_pos);}
size_t getCellNum() {return cell.size();}
//no locks
Cluster& getCluster(size_t p_pos) {return cluster.at(p_pos);}
size_t getClusterNum() {return cluster.size();}
// cell
//writers
void updateCell();
void addCell(size_t p_cell); /*{cell.push_back(p_cell); used_width += design.cell_lib[p_cell].width;}*/
void deleteCell(size_t p_cell_pos);/* {/*used_width -= design.cell_lib[getCell(p_cell_pos)].width; cell.erase(cell.begin() + p_cell_pos);}*/
// cluster
//no locks
void clearCluster() {cluster.clear();}
void deleteCluster(size_t p_cluster_pos) {cluster.erase(cluster.begin() + p_cluster_pos);}
//void updateCluster(size_t p_pos, Cluster p_new_cluster) {cluster.at(p_pos) = p_new_cluster;}
//void findCluster();
//void moveCluster();
// for legalize using
void setUsedWidth(coor_type p_width) {used_width = p_width;}
coor_type getUsedWidth() {return used_width;}
coor_type getUsedArea(coor_type p_left, coor_type p_right);
coor_type getUnusedWidth() {return width - used_width;}
// FatMinMin
private:
//Coor ll;
coor_type lx;
coor_type coordinate;// Y-coor
coor_type width;
coor_type height;
coor_type used_width;
vector<size_t> cell;
vector<Cluster> cluster;
}; // SubRow
SubRow& getCellSubrow(int cell_index);
SubRow& getCoorSubrow(Coor coor);
pair<int, int> getCellRowSubrowIndex(int cell_index);
pair<int, int> getWhitespaceRowSubrowIndex(SwapTarget target);
pair<int, int> getCoorRowSubrowIndex(Coor coor);