-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGArray.cc
98 lines (84 loc) · 1.93 KB
/
GArray.cc
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
//#include <malloc.h>
#include <stdlib.h>
#include "GArray.h"
#include "Util.h"
#ifdef SGI
/////////Template Instantiation Stuff////////////
#pragma instantiate GArray<int>
#pragma instantiate GArray<GArray<int>*>
////////////////////////////////////////////////
#endif
template <class Items>
void GArray<Items>::Realloc (int newlen)
{
totSz = Util<Items>::Realloc (newlen, sizeof(Items), theAry);
}
template <class Items>
GArray<Items>::GArray(int sz)
{
totSz = sz;
theSz=0;
theAry = NULL;
if (sz > 0) Util<Items>::Realloc(totSz,sizeof(Items), theAry);
}
template <class Items>
GArray<Items>::GArray(GArray<Items> *ary)
{
totSz = ary->totSz;
theSz=ary->theSz;
theAry = NULL;
if (theSz > 0){
Util<Items>::Realloc(totSz,sizeof(Items), theAry);
for (int i=0; i < theSz; i++)
theAry[i] = ary->theAry[i];
}
}
template <class Items>
GArray<Items>::~GArray()
{
if (theAry) free(theAry);
}
template <class Items>
void GArray<Items>::copy (GArray<Items> *ary)
{
theSz=ary->theSz;
for (int i=0; i < theSz; i++) theAry[i] = ary->theAry[i];
}
template <class Items>
void GArray<Items>::add(Items it)
{
if (theSz+1 > totSz){
Realloc(2*totSz);
}
theAry[theSz++] = it;
}
template <class Items>
void GArray<Items>::compact(int nsz)
{
if (nsz == -1)
Realloc(theSz);
else{
Realloc(nsz);
theSz = nsz;
}
}
ostream& operator << (ostream& fout, GArray<int>& ary){
for (int i=0; i < ary.theSz; i++)
fout << ary.theAry[i] << " ";
return fout;
}
template<class Items>
ostream& operator << (ostream& fout, GArray<Items>& ary){
return fout;
}
#ifdef __GNUC__
/////////Template Instantiation Stuff////////////
template class GArray<int>;
template class GArray<GArray<int>*>;
#include "Graph.h"
template class GArray<GrItem *>;
template class GArray<GrNode *>;
class iterstat;
template class GArray<iterstat *>;
////////////////////////////////////////////////
#endif