-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.cpp
More file actions
49 lines (43 loc) · 969 Bytes
/
Map.cpp
File metadata and controls
49 lines (43 loc) · 969 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
39
40
41
42
43
44
45
46
47
48
#include "Map.h"
using namespace std;
Mymap::Mymap(int size,int buffersize):size(size),buffersize(buffersize)
{
documents=(char**)malloc(size*sizeof(char*));
lengths=(int*)malloc(size*sizeof(int));
for(int i=0;i<size;i++)
documents[i]=(char*)malloc(buffersize*sizeof(char));
}
Mymap::~Mymap()
{
for(int i=0;i<size;i++)
free(documents[i]);
free(documents);
free(lengths);
}
int Mymap::insert(char* line, int i){
int cur;
char* token;
token = strtok(line, " \t");
// cout << token << endl;
cur = atoi(token);
if(cur!=i){
token=NULL;
free(token);
return -1;
}
token = strtok(NULL, "\n");
while(token[0]==' '){
token++;
}
int end = 0;
while(token[end] != '\0'){
end++;
}
end--;
while(end!=0 && token[end] == ' ')
token[end--] = '\0';
strcpy(documents[i], token);
token = NULL;
free(token);
return 1;
}