Skip to content

Commit 54799e3

Browse files
committed
fixing postfix increment/decrement, cleaning up hash set
1 parent e565571 commit 54799e3

17 files changed

+269
-164
lines changed

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ OBJECTS := $(SOURCES:%.cpp=%.o)
66
TEST_OBJECTS := $(TESTS:.cpp=.o)
77
DEPS := $(OBJECTS:.o=.d)
88
TEST_DEPS := $(TEST_OBJECTS:.o=.d)
9-
GTEST_I := -I$(GOOGLE_TEST_PATH)/include -I.
10-
GTEST_L := -L$(GOOGLE_TEST_PATH)/make -L.
9+
GTEST := ../googletest
10+
GTEST_I := -I$(GTEST)/include -I.
11+
GTEST_L := -L$(GTEST) -L.
1112
TARGET = libstdcore.a
1213
TEST_TARGET = test_stdcore
1314

@@ -30,12 +31,15 @@ std/%.o: std/%.cpp
3031
$(CXX) $(CXXFLAGS) -MM -MF $(patsubst %.o,%.d,$@) -MT $@ -c $<
3132
$(CXX) $(CXXFLAGS) -c -o $@ $<
3233

33-
$(TEST_TARGET): $(TEST_OBJECTS) $(GOOGLE_TEST_PATH)/make/gtest_main.o
34-
$(CXX) $(CXXFLAGS) $(GTEST_L) $^ -pthread -lstdcore -l:gtest.a -o $(TEST_TARGET)
34+
$(TEST_TARGET): $(TEST_OBJECTS) test/gtest_main.o
35+
$(CXX) $(CXXFLAGS) $(GTEST_L) $^ -pthread -lstdcore -lgtest -o $(TEST_TARGET)
3536

3637
test/%.o: test/%.cpp
3738
$(CXX) $(CXXFLAGS) $(GTEST_I) -MM -MF $(patsubst %.o,%.d,$@) -MT $@ -c $<
3839
$(CXX) $(CXXFLAGS) $(GTEST_I) $< -c -o $@
40+
41+
test/gtest_main.o: $(GTEST)/src/gtest_main.cc
42+
$(CXX) $(CXXFLAGS) $(GTEST_I) $< -c -o $@
3943

4044
clean:
4145
rm -f std/*.o test/*.o

std/array.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,18 @@ struct array
9696
return index;
9797
}
9898

99-
iterator &operator++(int)
99+
iterator operator++(int)
100100
{
101+
iterator result = *this;
101102
index++;
102-
return *this;
103+
return result;
103104
}
104105

105-
iterator &operator--(int)
106+
iterator operator--(int)
106107
{
108+
iterator result = *this;
107109
index--;
108-
return *this;
110+
return result;
109111
}
110112

111113
iterator &operator++()
@@ -509,16 +511,18 @@ struct array
509511
return index;
510512
}
511513

512-
const_iterator &operator++(int)
514+
const_iterator operator++(int)
513515
{
516+
const_iterator result = *this;
514517
index++;
515-
return *this;
518+
return result;
516519
}
517520

518-
const_iterator &operator--(int)
521+
const_iterator operator--(int)
519522
{
523+
const_iterator result = *this;
520524
index--;
521-
return *this;
525+
return result;
522526
}
523527

524528
const_iterator &operator++()

std/ascii_stream.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ void ascii_stream::flush(const char *path, int line)
3636
fwrite(store.data, 1, store.size(), ptr);
3737
fputs(end, ptr);
3838
}
39+
else
40+
fputs(end, ptr);
3941

4042
if (ptr != NULL)
4143
fflush(ptr);

std/ascii_stream.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ struct ascii_stream
2424
count = 0;
2525
}
2626

27+
ascii_stream(string filename, const char *end = "\n", const char *msg = NULL, bool debug = false)
28+
{
29+
ptr = fopen(filename.c_str(), "w");
30+
this->msg = msg;
31+
this->debug = debug;
32+
this->end = end;
33+
count = 0;
34+
}
35+
2736
ascii_stream(const char *filename, const char *end = "\n", const char *msg = NULL, bool debug = false)
2837
{
2938
ptr = fopen(filename, "w");

std/fill.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,18 @@ struct fill
8686
return index;
8787
}
8888

89-
const_iterator &operator++(int)
89+
const_iterator operator++(int)
9090
{
91+
const_iterator result = *this;
9192
index++;
92-
return *this;
93+
return result;
9394
}
9495

95-
const_iterator &operator--(int)
96+
const_iterator operator--(int)
9697
{
98+
const_iterator result = *this;
9799
index--;
98-
return *this;
100+
return result;
99101
}
100102

101103
const_iterator &operator++()

std/graph.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,18 @@ struct graph
117117
return loc->index;
118118
}
119119

120-
iterator &operator++(int)
120+
iterator operator++(int)
121121
{
122+
iterator result = *this;
122123
loc = loc->right;
123-
return *this;
124+
return result;
124125
}
125126

126-
iterator &operator--(int)
127+
iterator operator--(int)
127128
{
129+
iterator result = *this;
128130
loc = loc->left;
129-
return *this;
131+
return result;
130132
}
131133

132134
iterator &operator++()
@@ -398,16 +400,18 @@ struct graph
398400
return loc->index;
399401
}
400402

401-
const_iterator &operator++(int)
403+
const_iterator operator++(int)
402404
{
405+
const_iterator result = *this;
403406
loc = loc->right;
404-
return *this;
407+
return result;
405408
}
406409

407-
const_iterator &operator--(int)
410+
const_iterator operator--(int)
408411
{
412+
const_iterator result = *this;
409413
loc = loc->left;
410-
return *this;
414+
return result;
411415
}
412416

413417
const_iterator &operator++()

std/hash_map.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ struct hash_map : hash_set<implier<key_type, value_type>, hash_func>
2626
using super::rbegin;
2727
using super::rend;
2828
using super::insert;
29-
using super::find;
3029
using super::contains;
3130

3231
hash_map()
@@ -51,6 +50,11 @@ struct hash_map : hash_set<implier<key_type, value_type>, hash_func>
5150
return super::insert(implier<key_type, value_type>(key, value));
5251
}
5352

53+
iterator insert_duplicate(key_type key, value_type value)
54+
{
55+
return super::insert_duplicate(implier<key_type, value_type>(key, value));
56+
}
57+
5458
iterator find(key_type key)
5559
{
5660
return super::find(implier<key_type, value_type>(key, value_type()));
@@ -63,7 +67,7 @@ struct hash_map : hash_set<implier<key_type, value_type>, hash_func>
6367

6468
bool contains(key_type key) const
6569
{
66-
return find(key) != end();
70+
return contains(implier<key_type, value_type>(key, value_type()));
6771
}
6872
};
6973

0 commit comments

Comments
 (0)