Skip to content

Commit 9bf2889

Browse files
committed
inline optimize
1 parent 48d912c commit 9bf2889

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

include/heap.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ namespace alg
4949
KV * m_kvs;// key value pairs.
5050

5151
public:
52-
Heap(int max) {
52+
Heap(int max)
53+
{
5354
m_size = 0;
5455
m_max = max+1;
5556
m_kvs = new KV[m_max];
5657
m_kvs[0].key = INT_MIN;
5758
};
5859

59-
~Heap() {
60+
~Heap()
61+
{
6062
delete [] m_kvs;
6163
};
6264

@@ -172,7 +174,7 @@ namespace alg
172174
* step 1. find the value
173175
* step 2. decrease the key to the newkey
174176
*/
175-
inline void decrease_key(const T & value, int newkey)
177+
void decrease_key(const T & value, int newkey)
176178
{
177179
uint32_t index = m_size+1;
178180
for (uint32_t i=1;i<=m_size;i++) {

include/lcs.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ namespace alg
3737
7 Z 0 1 2 2 3 3 3 4
3838
*/
3939
template<typename T>
40-
static Array2D<uint32_t> *
41-
lcs_length(const T X[], uint32_t m, const T Y[], uint32_t n)
40+
static Array2D<uint32_t> * lcs_length(const T X[], uint32_t m, const T Y[], uint32_t n)
4241
{
4342
Array2D<uint32_t> & A = *new Array2D<uint32_t>(m+1,n+1);
4443

@@ -67,8 +66,7 @@ namespace alg
6766
* pass an empty stack, pop out the result in sequential order.
6867
*/
6968
template<typename T>
70-
static void
71-
lcs_backtrack(Stack<int> & S, struct Array2D<uint32_t> & A,
69+
static void lcs_backtrack(Stack<int> & S, struct Array2D<uint32_t> & A,
7270
const T X[], const T Y[],
7371
const uint32_t i, uint32_t j)
7472
{

include/priority_queue.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ namespace alg
105105
* return top element
106106
* check is_empty() before top().
107107
*/
108-
const T & top(int * prio) const
108+
inline const T & top(int * prio) const
109109
{
110110
PQNode * n;
111111
n = list_entry(m_head.next, PQNode, node);
@@ -116,7 +116,7 @@ namespace alg
116116
/**
117117
* dequeue the most priority element, i.e. the first element.
118118
*/
119-
void dequeue()
119+
inline void dequeue()
120120
{
121121
if (list_empty(&m_head)) return;
122122

@@ -130,7 +130,8 @@ namespace alg
130130
/**
131131
* test whether the priority queue is empty
132132
*/
133-
inline bool is_empty() const {
133+
inline bool is_empty() const
134+
{
134135
if (list_empty(&m_head)) return true;
135136
return false;
136137
}

include/queue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ namespace alg
103103
/**
104104
* test weather the queue is empty
105105
*/
106-
bool is_empty() const
106+
inline bool is_empty() const
107107
{
108108
if (m_size ==0) return true;
109109
return false;

include/stack.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,20 @@ class Stack
8383
/**
8484
* pop stack
8585
*/
86-
inline void pop() {
86+
inline void pop()
87+
{
8788
if(m_size!=0) m_size--;
8889
return;
8990
}
9091

9192
/**
9293
* get the top element
9394
*/
94-
inline const T& top() const {
95+
inline const T& top() const
96+
{
9597
if (m_size==0) throw exp_empty;
9698
return m_elements[m_size-1];
97-
};
99+
}
98100

99101
/**
100102
* push an element into the stack
@@ -117,7 +119,8 @@ class Stack
117119
/**
118120
* return value by index
119121
*/
120-
inline const T& operator[] (int idx) const {
122+
inline const T& operator[] (int idx) const
123+
{
121124
if (idx<0 || idx >= m_capacity) throw exp_ioob;
122125
return m_elements[m_size-1-idx];
123126
}

0 commit comments

Comments
 (0)