1
0
ithewei 7 жил өмнө
parent
commit
10fe530cce
2 өөрчлөгдсөн 0 нэмэгдсэн , 96 устгасан
  1. 0 52
      htable.cpp
  2. 0 44
      htable.h

+ 0 - 52
htable.cpp

@@ -1,52 +0,0 @@
-#include "htable.h"
-
-#include "hdef.h"
-
-HTable::HTable() {
-    row = col = 0;
-}
-
-void HTable::init(int row, int col) {
-    this->row = row;
-    this->col = col;
-    m_mapCells.clear();
-    for (int r = 1; r <= row; ++r) {
-        for (int c = 1; c <= col; ++c) {
-            int id = (r-1) * col + c;
-            m_mapCells[id] = HTableCell(r, r, c, c);
-        }
-    }
-}
-
-bool HTable::getTableCell(int id, HTableCell& rst) {
-    if (m_mapCells.find(id) != m_mapCells.end()) {
-        rst = m_mapCells[id];
-        return true;
-    }
-    return false;
-}
-
-HTableCell HTable::merge(int lt, int rb) {
-    HTableCell cell_lt, cell_rb;
-    if (getTableCell(lt, cell_lt) && getTableCell(rb, cell_rb)) {
-        int r1 = MIN(cell_lt.r1, cell_rb.r1);
-        int r2 = MAX(cell_lt.r2, cell_rb.r2);
-        int c1 = MIN(cell_lt.c1, cell_rb.c1);
-        int c2 = MAX(cell_lt.c2, cell_rb.c2);
-
-        HTableCell cell(r1, r2, c1, c2);
-        std::map<int, HTableCell>::iterator iter = m_mapCells.begin();
-        while (iter != m_mapCells.end()) {
-            if (cell.contain(iter->second)) {
-                iter = m_mapCells.erase(iter);
-            } else {
-                ++iter;
-            }
-        }
-        m_mapCells[lt] = cell;
-
-        return cell;
-    }
-
-    return HTableCell();
-}

+ 0 - 44
htable.h

@@ -1,44 +0,0 @@
-#ifndef HW_TABLE_H_
-#define HW_TABLE_H_
-
-#include <map>
-
-class HTableCell {
- public:
-    HTableCell() {r1 = r2 = c1 = c2 = 0;}
-    HTableCell(int r1, int r2, int c1, int c2) {
-        this->r1 = r1;
-        this->r2 = r2;
-        this->c1 = c1;
-        this->c2 = c2;
-    }
-
-    int rowspan() {return r2 - r1 + 1;}
-    int colspan() {return c2 - c1 + 1;}
-    int span() {return rowspan() * colspan();}
-
-    bool contain(HTableCell cell) {
-        if (cell.r1 >= r1 && cell.r2 <= r2 &&
-            cell.c1 >= c1 && cell.c2 <= c2)
-            return true;
-        return false;
-    }
-
-    int r1, r2, c1, c2;
-};
-
-class HTable {
- public:
-    HTable();
-
-    void init(int row, int col);
-    bool getTableCell(int id, HTableCell& rst);
-    HTableCell merge(int lt, int rb);
-
- public:
-    int row;
-    int col;
-    std::map<int, HTableCell> m_mapCells;   // id => HTabelCell
-};
-
-#endif  // HW_TABLE_H_