-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathastring.cpp
More file actions
38 lines (30 loc) · 891 Bytes
/
astring.cpp
File metadata and controls
38 lines (30 loc) · 891 Bytes
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
#include "astring.h"
Astr::Astr(const char* string)
{
*m_length = strlen(string);
*m_lengthT = *m_length + 1;
*m_numBlocks = (*m_lengthT / StrBLock::BLOCK_SIZE) + 1;
m_ptrs = new StrBLock* [*m_numBlocks];
int currentBlock = 0;
int currentBlockIndex = 0;
m_ptrs[currentBlock] = new StrBLock();
for (int i = 0; i < *m_lengthT; ++i){
if(currentBlockIndex == StrBLock::BLOCK_SIZE){
++currentBlock;
m_ptrs[currentBlock] = new StrBLock();
currentBlockIndex = 0;
}
m_ptrs[currentBlock]->set(string[i], currentBlockIndex);
++currentBlockIndex;
}
}
Astr::~Astr(){
for (int i = 0; i < *m_numBlocks; ++i){
delete m_ptrs[i];
m_ptrs[i] = nullptr;
}
delete [] m_ptrs;
delete m_length;
delete m_lengthT;
delete m_numBlocks;
}