Skip to content

Commit 2c66785

Browse files
1. Removed the Timestamp class and replaced it with primitive long types
2. Created a minimal timestamp.h header for backward compatibility with NOT_SET defined as -1 3. Updated all method signatures and implementations to use long instead of Timestamp 4. Fixed comparisons with NOT_SET to use -1 directly 5. Updated the Phase class to properly implement the ProcessingPhase interface 6. Added proper toString() method to the Phase class for easier debugging
1 parent be5b961 commit 2c66785

File tree

11 files changed

+68
-61
lines changed

11 files changed

+68
-61
lines changed

include/network/activation.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "network/binding_signal.h"
1313
#include "network/link.h"
1414
#include "network/fired.h"
15-
#include "network/timestamp.h"
1615

1716
#include <map>
1817
#include <set>
@@ -47,11 +46,11 @@ class Activation : public Obj, public Element, public ModelProvider {
4746
virtual void linkIncoming(Activation* excludedInputAct) = 0;
4847
std::set<Activation*> collectLinkingTargets(Neuron* n);
4948
int getId();
50-
Timestamp getCreated();
51-
void setCreated(Timestamp ts);
52-
Timestamp getFired();
49+
long getCreated() override;
50+
void setCreated(long ts);
51+
long getFired() override;
5352
void setFired();
54-
void setFired(Timestamp f);
53+
void setFired(long f);
5554
void updateFiredStep(Field* net);
5655
Queue* getQueue();
5756
Neuron* getNeuron();

include/network/element.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#ifndef NETWORK_ELEMENT_H
22
#define NETWORK_ELEMENT_H
33

4-
#include "network/timestamp.h"
54
#include "fields/queue_provider.h"
65

76
class Element : public QueueProvider {
87
public:
98
virtual ~Element() = default;
10-
virtual Timestamp getCreated() = 0;
11-
virtual Timestamp getFired() = 0;
9+
virtual long getCreated() = 0;
10+
virtual long getFired() = 0;
1211
};
1312

1413
#endif // NETWORK_ELEMENT_H

include/network/fired.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "fields/queue.h"
66
#include "network/activation.h"
77
#include "network/phase.h"
8-
#include "network/timestamp.h"
98
#include <string>
109

1110
class Fired : public Step {

include/network/fired_queue_key.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
#ifndef NETWORK_FIRED_QUEUE_KEY_H
22
#define NETWORK_FIRED_QUEUE_KEY_H
33

4-
#include "network/queue_key.h"
4+
#include "fields/queue_key.h"
55
#include "network/element.h"
6-
#include "network/processing_phase.h"
7-
#include "network/timestamp.h"
86
#include <string>
97
#include <functional>
108

119
class FiredQueueKey : public QueueKey {
1210
public:
13-
FiredQueueKey(int round, ProcessingPhase phase, Element* element, Timestamp currentTimestamp);
11+
FiredQueueKey(int round, const ProcessingPhase& phase, Element* element, long currentTimestamp);
1412

15-
Timestamp getFired() const;
16-
Timestamp getCreated() const;
13+
long getFired() const;
14+
long getCreated() const;
1715
std::string toString() const override;
1816
int compareTo(QueueKey* qk) const override;
1917

2018
private:
2119
static const std::function<int(const FiredQueueKey*, const FiredQueueKey*)> COMPARATOR;
2220

23-
Timestamp created;
24-
Timestamp fired;
21+
long created;
22+
long fired;
2523
};
2624

2725
#endif // NETWORK_FIRED_QUEUE_KEY_H

include/network/link.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class Link : public Obj, public Element, public ModelProvider {
2222

2323
RelatedObjectIterable* followManyRelation(Relation* rel) const override;
2424
Obj* followSingleRelation(const Relation* rel) override;
25-
Timestamp getFired() override;
26-
Timestamp getCreated() override;
25+
long getFired() override;
26+
long getCreated() override;
2727
Synapse* getSynapse();
2828
void setSynapse(Synapse* synapse);
2929
Activation* getInput();

include/network/neuron.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ class Neuron : public Obj, public Element, public ModelProvider {
4848
Synapse* getOutputSynapseByType(Type* synapseType) const;
4949
std::vector<Synapse*> getOutputSynapsesByType(Type* synapseType) const;
5050
Synapse* selectInputSynapse(std::function<bool(Synapse*)> predicate) const;
51-
Timestamp getCreated() override;
52-
Timestamp getFired() override;
51+
long getCreated() override;
52+
long getFired() override;
5353
Queue* getQueue() override;
5454
void increaseRefCount(RefType rt);
5555
void decreaseRefCount(RefType rt);

include/network/phase.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define NETWORK_PHASE_H
33

44
#include "fields/queue_key.h"
5+
#include <string>
56

67
// First define the enum for Phase types
78
enum class PhaseType {
@@ -14,7 +15,7 @@ enum class PhaseType {
1415
};
1516

1617
// Phase class that implements ProcessingPhase interface
17-
class Phase : public ProcessingPhase {
18+
class Phase final : public ProcessingPhase {
1819
public:
1920
Phase(PhaseType type) : type(type) {}
2021

@@ -34,6 +35,19 @@ class Phase : public ProcessingPhase {
3435
return type == PhaseType::SAVE; // Only SAVE phase is delayed
3536
}
3637

38+
// For string representation
39+
std::string toString() const {
40+
switch (type) {
41+
case PhaseType::INFERENCE: return "INFERENCE";
42+
case PhaseType::FIRED: return "FIRED";
43+
case PhaseType::INSTANTIATION_TRIGGER: return "INSTANTIATION_TRIGGER";
44+
case PhaseType::TRAINING: return "TRAINING";
45+
case PhaseType::INACTIVE_LINKS: return "INACTIVE_LINKS";
46+
case PhaseType::SAVE: return "SAVE";
47+
default: return "UNKNOWN";
48+
}
49+
}
50+
3751
// Static instances for convenience
3852
static const Phase INFERENCE;
3953
static const Phase FIRED;

include/network/synapse.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ class Synapse : public Obj, public Element {
6363
virtual void readFields(DataInput* in, TypeRegistry* tr) = 0;
6464
*/
6565

66-
Timestamp getCreated() const override;
67-
Timestamp getFired() const override;
66+
long getCreated() const override;
67+
long getFired() const override;
6868

6969
void deleteSynapse(Model* m);
7070

include/network/timestamp.h

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,11 @@
11
#ifndef NETWORK_TIMESTAMP_H
22
#define NETWORK_TIMESTAMP_H
33

4-
#include <string>
4+
// This is a compatibility header.
5+
// The Timestamp class has been replaced with direct use of long values.
6+
// The constant Timestamp::NOT_SET has been replaced with the value -1.
57

6-
class Timestamp {
7-
public:
8-
static const Timestamp NOT_SET;
8+
// For backwards compatibility, define NOT_SET as -1
9+
constexpr long NOT_SET = -1;
910

10-
Timestamp();
11-
Timestamp(long time);
12-
13-
long getTime() const;
14-
void setTime(long time);
15-
16-
bool operator==(const Timestamp& other) const;
17-
bool operator!=(const Timestamp& other) const;
18-
bool operator<(const Timestamp& other) const;
19-
bool operator>(const Timestamp& other) const;
20-
bool operator<=(const Timestamp& other) const;
21-
bool operator>=(const Timestamp& other) const;
22-
23-
std::string toString() const;
24-
25-
private:
26-
long time;
27-
};
28-
29-
#endif // NETWORK_TIMESTAMP_H
11+
#endif // NETWORK_TIMESTAMP_H

src/network/activation.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const std::function<bool(Activation*, Activation*)> Activation::ID_COMPARATOR =
99
};
1010

1111
Activation::Activation(ActivationDefinition* t, Activation* parent, int id, Neuron* n, Document* doc, std::map<BSType, BindingSignal*> bindingSignals)
12-
: Obj(t), id(id), neuron(n), doc(doc), bindingSignals(bindingSignals), parent(parent), created(Timestamp::NOT_SET), fired(Timestamp::NOT_SET), firedStep(new Fired(this)) {
12+
: Obj(t), id(id), neuron(n), doc(doc), bindingSignals(bindingSignals), parent(parent), created(-1), fired(-1), firedStep(new Fired(this)) {
1313
doc->addActivation(this);
1414
neuron->updateLastUsed(doc->getId());
1515
setCreated(doc->getCurrentTimestamp());
@@ -147,28 +147,28 @@ int Activation::getId() {
147147
return id;
148148
}
149149

150-
Timestamp Activation::getCreated() {
150+
long Activation::getCreated() {
151151
return created;
152152
}
153153

154-
void Activation::setCreated(Timestamp ts) {
154+
void Activation::setCreated(long ts) {
155155
created = ts;
156156
}
157157

158-
Timestamp Activation::getFired() {
158+
long Activation::getFired() {
159159
return fired;
160160
}
161161

162162
void Activation::setFired() {
163163
fired = doc->getCurrentTimestamp();
164164
}
165165

166-
void Activation::setFired(Timestamp f) {
166+
void Activation::setFired(long f) {
167167
fired = f;
168168
}
169169

170170
void Activation::updateFiredStep(Field* net) {
171-
if (!net->exceedsThreshold() || fired != Timestamp::NOT_SET) {
171+
if (!net->exceedsThreshold() || fired != -1) {
172172
return;
173173
}
174174

0 commit comments

Comments
 (0)