-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointerSpace.cpp
More file actions
executable file
·145 lines (125 loc) · 4.16 KB
/
pointerSpace.cpp
File metadata and controls
executable file
·145 lines (125 loc) · 4.16 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
This class is supposed to act as a base class for all other toy and real programs based upon things bound or iteracting with each other.
There is no limit on the number of pointers which may be held in each existence. To have two separate spaces interating with each other must have wrapper class,
probably call this interactionSpace (or something).
All it is is a list of lists of pointers whose first members are pointing at itself, and methods to manipulate it.
All lists are private and returned in the getters.
There is a list of list<pointer>.begin()'s (npointers) returned in a get. This list corresponds to the initial conditions
of the first elements in each of the lists of pointers held in the exist list.
*/
#include "pointerSpace.h"
using namespace std ;
// list<list::iterator> npointers ;
// list<list::iterator>::iterator n ;
// list<list<list::iterator>> exist ;
// CONSTRUCTOR
void pointerSpace::pointerSpace(int N)
{
//point the first instance of birth at itself (birth is temp)
//populate npointers with the start of each birthed existence
//put it in existence
for(int i = 0 ; i <= N ; i++){
list<list::iterator> birth ;
n = birth.begin() ;
birth.push_back(n) ;
npointers.push_back(n) ;
exist.push_back(birth) ;
}
nExistences = exist.size() ;
histories = 0 ;
}
// RETURN METHODS
list<list::iterator> pointerSpace::furthests()
{
list<list::iterator> lasts ;
list<list<list::iterator>>::iterator e ;
for(e = exist.begin() ; e != exist.end() ; e++){
ends.push_back((*e).last()) ;
}
return ends ;
}
list<list::iterator> pointerSpace::closest() // unless manipulated this will return the same as addresses()
{
list<list::iterator> firsts ;
list<list<list::iterator>>::iterator e ;
for(e = exist.begin() ; e != exist.end() ; e++){
firsts.push_back((*e).first()) ;
}
return firsts ;
}
list<list::iterator> pointerSpace::closests() ; // this should return the first friend (that is not self)
{
list<list::iterator> seconds ;
list<list<list::iterator>>::iterator e ;
for(e = exist.begin() ; e != exist.end() ; e++){
n = (*e).begin() ;
n++ ;
seconds.push_back((*n)) ;
}
return seconds ;
}
list<list<list::iterator>> pointerSpace::state() // this makes exist accessable, maybe dont need to return friends..its here anyway.
{
histories ++ ;
return exist ;
}
int pointerSpace::size()
{
return nExitences ;
}
list<list::iterator> pointerSpace::addresses()
{
return npointers ;
}
list<list::iterator> pointerSpace::myFriends(/*list<list<list::iterator>::iterator me*/int me)
{
list<list<list::iterator>::iterator e = exist.begin() ;
for(int i = 0 ; i < me ; i++, e++){}
return *e ;
// TEST METHODS
bool pointerSpace::friendsWith(list<list<list::iterator>>::iterator friend_1, list<list<list::iterator>>::iterator friend_2)
{
if((*friend_1).contains(friend_2) && (*friend_2).contains(friend_1)) return true ;
return false ;
}
int pointerSpace::findBinA(list<list<list::iterator>>::iterator A, list<list<list::iterator>>::iterator B)
{
list<list::iterator>::iterator searcher = (*A).begin() ;
int i = 0 ;
for(searcher != (*A).end() ; searcher++, i++){
if(*searcher == B) return i ;
i++
}
return -1 ;
}
// MANIPULATION METHODS
int pointerSpace::shortenAll(int N)
{
int n_smaller = 0 ;
list<list<list::iterator>>::iterator e ;
for(e = exist.begin() ; e != exist.end() ; e++){
while((*e).size() > N) (*e).pop_back() ;
if((*e).size() < N) n_smaller ++ ;
}
return n_smaller ;
}
int pointerSpace::meet(list<list<list::iterator>>::iterator friend_1, list<list<list::iterator>>::iterator friend_2) //must make 'shun' method to remove friends.
{
if(!friends(friend_1, friend_2)){
(*friend_1).push_back(friend_2) ;
(*friend_2).push_back(friend_1) ;
return 0 ;
}
if(friends(friend_1, friend_2)) return 2 ;
else if((*friend_1).contains(friend_2)) return 1 ;
else if((*friend_2).contains(friend_1)) return -1 ;
}
void pointerSpace::meetAll()
{
list<list<list::iterator>>::iterator e ;
for(n = npointers.begin() ; n != npointers.end() ; n++){
for(e = exist.begin() ; exist != exist.end() ; e++){
(*e).push_back(*n) ;
}
}
}