cppjieba_rb 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +3 -0
- data/README.md +1 -1
- data/Rakefile +2 -2
- data/cppjieba_rb.gemspec +4 -4
- data/lib/cppjieba_rb/version.rb +1 -1
- metadata +17 -135
- data/ext/cppjieba/.gitignore +0 -17
- data/ext/cppjieba/.travis.yml +0 -21
- data/ext/cppjieba/CMakeLists.txt +0 -28
- data/ext/cppjieba/ChangeLog.md +0 -236
- data/ext/cppjieba/README.md +0 -292
- data/ext/cppjieba/README_EN.md +0 -113
- data/ext/cppjieba/appveyor.yml +0 -32
- data/ext/cppjieba/deps/CMakeLists.txt +0 -1
- data/ext/cppjieba/deps/gtest/CMakeLists.txt +0 -5
- data/ext/cppjieba/deps/gtest/include/gtest/gtest-death-test.h +0 -283
- data/ext/cppjieba/deps/gtest/include/gtest/gtest-message.h +0 -230
- data/ext/cppjieba/deps/gtest/include/gtest/gtest-param-test.h +0 -1421
- data/ext/cppjieba/deps/gtest/include/gtest/gtest-param-test.h.pump +0 -487
- data/ext/cppjieba/deps/gtest/include/gtest/gtest-printers.h +0 -796
- data/ext/cppjieba/deps/gtest/include/gtest/gtest-spi.h +0 -232
- data/ext/cppjieba/deps/gtest/include/gtest/gtest-test-part.h +0 -176
- data/ext/cppjieba/deps/gtest/include/gtest/gtest-typed-test.h +0 -259
- data/ext/cppjieba/deps/gtest/include/gtest/gtest.h +0 -2155
- data/ext/cppjieba/deps/gtest/include/gtest/gtest_pred_impl.h +0 -358
- data/ext/cppjieba/deps/gtest/include/gtest/gtest_prod.h +0 -58
- data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-death-test-internal.h +0 -308
- data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-filepath.h +0 -210
- data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-internal.h +0 -1226
- data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-linked_ptr.h +0 -233
- data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-param-util-generated.h +0 -4822
- data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-param-util-generated.h.pump +0 -301
- data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-param-util.h +0 -619
- data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-port.h +0 -1788
- data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-string.h +0 -350
- data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-tuple.h +0 -968
- data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-tuple.h.pump +0 -336
- data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-type-util.h +0 -3330
- data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-type-util.h.pump +0 -296
- data/ext/cppjieba/deps/gtest/src/.deps/.dirstamp +0 -0
- data/ext/cppjieba/deps/gtest/src/.deps/gtest-all.Plo +0 -681
- data/ext/cppjieba/deps/gtest/src/.deps/gtest_main.Plo +0 -509
- data/ext/cppjieba/deps/gtest/src/.dirstamp +0 -0
- data/ext/cppjieba/deps/gtest/src/gtest-all.cc +0 -48
- data/ext/cppjieba/deps/gtest/src/gtest-death-test.cc +0 -1234
- data/ext/cppjieba/deps/gtest/src/gtest-filepath.cc +0 -380
- data/ext/cppjieba/deps/gtest/src/gtest-internal-inl.h +0 -1038
- data/ext/cppjieba/deps/gtest/src/gtest-port.cc +0 -746
- data/ext/cppjieba/deps/gtest/src/gtest-printers.cc +0 -356
- data/ext/cppjieba/deps/gtest/src/gtest-test-part.cc +0 -110
- data/ext/cppjieba/deps/gtest/src/gtest-typed-test.cc +0 -110
- data/ext/cppjieba/deps/gtest/src/gtest.cc +0 -4898
- data/ext/cppjieba/deps/gtest/src/gtest_main.cc +0 -39
- data/ext/cppjieba/deps/limonp/ArgvContext.hpp +0 -70
- data/ext/cppjieba/deps/limonp/BlockingQueue.hpp +0 -49
- data/ext/cppjieba/deps/limonp/BoundedBlockingQueue.hpp +0 -67
- data/ext/cppjieba/deps/limonp/BoundedQueue.hpp +0 -65
- data/ext/cppjieba/deps/limonp/Closure.hpp +0 -206
- data/ext/cppjieba/deps/limonp/Colors.hpp +0 -31
- data/ext/cppjieba/deps/limonp/Condition.hpp +0 -38
- data/ext/cppjieba/deps/limonp/Config.hpp +0 -103
- data/ext/cppjieba/deps/limonp/FileLock.hpp +0 -74
- data/ext/cppjieba/deps/limonp/ForcePublic.hpp +0 -7
- data/ext/cppjieba/deps/limonp/LocalVector.hpp +0 -139
- data/ext/cppjieba/deps/limonp/Logging.hpp +0 -76
- data/ext/cppjieba/deps/limonp/Md5.hpp +0 -411
- data/ext/cppjieba/deps/limonp/MutexLock.hpp +0 -51
- data/ext/cppjieba/deps/limonp/NonCopyable.hpp +0 -21
- data/ext/cppjieba/deps/limonp/StdExtension.hpp +0 -159
- data/ext/cppjieba/deps/limonp/StringUtil.hpp +0 -365
- data/ext/cppjieba/deps/limonp/Thread.hpp +0 -44
- data/ext/cppjieba/deps/limonp/ThreadPool.hpp +0 -86
- data/ext/cppjieba/dict/README.md +0 -31
- data/ext/cppjieba/dict/hmm_model.utf8 +0 -34
- data/ext/cppjieba/dict/idf.utf8 +0 -258826
- data/ext/cppjieba/dict/jieba.dict.utf8 +0 -348982
- data/ext/cppjieba/dict/pos_dict/char_state_tab.utf8 +0 -6653
- data/ext/cppjieba/dict/pos_dict/prob_emit.utf8 +0 -166
- data/ext/cppjieba/dict/pos_dict/prob_start.utf8 +0 -259
- data/ext/cppjieba/dict/pos_dict/prob_trans.utf8 +0 -5222
- data/ext/cppjieba/dict/stop_words.utf8 +0 -1534
- data/ext/cppjieba/dict/user.dict.utf8 +0 -4
- data/ext/cppjieba/include/cppjieba/DictTrie.hpp +0 -277
- data/ext/cppjieba/include/cppjieba/FullSegment.hpp +0 -93
- data/ext/cppjieba/include/cppjieba/HMMModel.hpp +0 -129
- data/ext/cppjieba/include/cppjieba/HMMSegment.hpp +0 -190
- data/ext/cppjieba/include/cppjieba/Jieba.hpp +0 -130
- data/ext/cppjieba/include/cppjieba/KeywordExtractor.hpp +0 -153
- data/ext/cppjieba/include/cppjieba/MPSegment.hpp +0 -137
- data/ext/cppjieba/include/cppjieba/MixSegment.hpp +0 -109
- data/ext/cppjieba/include/cppjieba/PosTagger.hpp +0 -77
- data/ext/cppjieba/include/cppjieba/PreFilter.hpp +0 -54
- data/ext/cppjieba/include/cppjieba/QuerySegment.hpp +0 -90
- data/ext/cppjieba/include/cppjieba/SegmentBase.hpp +0 -46
- data/ext/cppjieba/include/cppjieba/SegmentTagged.hpp +0 -23
- data/ext/cppjieba/include/cppjieba/TextRankExtractor.hpp +0 -190
- data/ext/cppjieba/include/cppjieba/Trie.hpp +0 -174
- data/ext/cppjieba/include/cppjieba/Unicode.hpp +0 -227
- data/ext/cppjieba/test/CMakeLists.txt +0 -5
- data/ext/cppjieba/test/demo.cpp +0 -80
- data/ext/cppjieba/test/load_test.cpp +0 -54
- data/ext/cppjieba/test/testdata/curl.res +0 -1
- data/ext/cppjieba/test/testdata/extra_dict/jieba.dict.small.utf8 +0 -109750
- data/ext/cppjieba/test/testdata/gbk_dict/hmm_model.gbk +0 -34
- data/ext/cppjieba/test/testdata/gbk_dict/jieba.dict.gbk +0 -348982
- data/ext/cppjieba/test/testdata/jieba.dict.0.1.utf8 +0 -93
- data/ext/cppjieba/test/testdata/jieba.dict.0.utf8 +0 -93
- data/ext/cppjieba/test/testdata/jieba.dict.1.utf8 +0 -67
- data/ext/cppjieba/test/testdata/jieba.dict.2.utf8 +0 -64
- data/ext/cppjieba/test/testdata/load_test.urls +0 -2
- data/ext/cppjieba/test/testdata/review.100 +0 -100
- data/ext/cppjieba/test/testdata/review.100.res +0 -200
- data/ext/cppjieba/test/testdata/server.conf +0 -19
- data/ext/cppjieba/test/testdata/testlines.gbk +0 -9
- data/ext/cppjieba/test/testdata/testlines.utf8 +0 -8
- data/ext/cppjieba/test/testdata/userdict.2.utf8 +0 -1
- data/ext/cppjieba/test/testdata/userdict.english +0 -2
- data/ext/cppjieba/test/testdata/userdict.utf8 +0 -8
- data/ext/cppjieba/test/testdata/weicheng.utf8 +0 -247
- data/ext/cppjieba/test/unittest/CMakeLists.txt +0 -24
- data/ext/cppjieba/test/unittest/gtest_main.cpp +0 -39
- data/ext/cppjieba/test/unittest/jieba_test.cpp +0 -133
- data/ext/cppjieba/test/unittest/keyword_extractor_test.cpp +0 -79
- data/ext/cppjieba/test/unittest/pos_tagger_test.cpp +0 -41
- data/ext/cppjieba/test/unittest/pre_filter_test.cpp +0 -43
- data/ext/cppjieba/test/unittest/segments_test.cpp +0 -256
- data/ext/cppjieba/test/unittest/textrank_test.cpp +0 -86
- data/ext/cppjieba/test/unittest/trie_test.cpp +0 -177
- data/ext/cppjieba/test/unittest/unicode_test.cpp +0 -43
@@ -1,31 +0,0 @@
|
|
1
|
-
#ifndef LIMONP_COLOR_PRINT_HPP
|
2
|
-
#define LIMONP_COLOR_PRINT_HPP
|
3
|
-
|
4
|
-
#include <string>
|
5
|
-
#include <stdarg.h>
|
6
|
-
|
7
|
-
namespace limonp {
|
8
|
-
|
9
|
-
using std::string;
|
10
|
-
|
11
|
-
enum Color {
|
12
|
-
BLACK = 30,
|
13
|
-
RED,
|
14
|
-
GREEN,
|
15
|
-
YELLOW,
|
16
|
-
BLUE,
|
17
|
-
PURPLE
|
18
|
-
}; // enum Color
|
19
|
-
|
20
|
-
static void ColorPrintln(enum Color color, const char * fmt, ...) {
|
21
|
-
va_list ap;
|
22
|
-
printf("\033[0;%dm", color);
|
23
|
-
va_start(ap, fmt);
|
24
|
-
vprintf(fmt, ap);
|
25
|
-
va_end(ap);
|
26
|
-
printf("\033[0m\n"); // if not \n , in some situation , the next lines will be set the same color unexpectedly
|
27
|
-
}
|
28
|
-
|
29
|
-
} // namespace limonp
|
30
|
-
|
31
|
-
#endif // LIMONP_COLOR_PRINT_HPP
|
@@ -1,38 +0,0 @@
|
|
1
|
-
#ifndef LIMONP_CONDITION_HPP
|
2
|
-
#define LIMONP_CONDITION_HPP
|
3
|
-
|
4
|
-
#include "MutexLock.hpp"
|
5
|
-
|
6
|
-
namespace limonp {
|
7
|
-
|
8
|
-
class Condition : NonCopyable {
|
9
|
-
public:
|
10
|
-
explicit Condition(MutexLock& mutex)
|
11
|
-
: mutex_(mutex) {
|
12
|
-
XCHECK(!pthread_cond_init(&pcond_, NULL));
|
13
|
-
}
|
14
|
-
|
15
|
-
~Condition() {
|
16
|
-
XCHECK(!pthread_cond_destroy(&pcond_));
|
17
|
-
}
|
18
|
-
|
19
|
-
void Wait() {
|
20
|
-
XCHECK(!pthread_cond_wait(&pcond_, mutex_.GetPthreadMutex()));
|
21
|
-
}
|
22
|
-
|
23
|
-
void Notify() {
|
24
|
-
XCHECK(!pthread_cond_signal(&pcond_));
|
25
|
-
}
|
26
|
-
|
27
|
-
void NotifyAll() {
|
28
|
-
XCHECK(!pthread_cond_broadcast(&pcond_));
|
29
|
-
}
|
30
|
-
|
31
|
-
private:
|
32
|
-
MutexLock& mutex_;
|
33
|
-
pthread_cond_t pcond_;
|
34
|
-
}; // class Condition
|
35
|
-
|
36
|
-
} // namespace limonp
|
37
|
-
|
38
|
-
#endif // LIMONP_CONDITION_HPP
|
@@ -1,103 +0,0 @@
|
|
1
|
-
/************************************
|
2
|
-
* file enc : utf8
|
3
|
-
* author : wuyanyi09@gmail.com
|
4
|
-
************************************/
|
5
|
-
#ifndef LIMONP_CONFIG_H
|
6
|
-
#define LIMONP_CONFIG_H
|
7
|
-
|
8
|
-
#include <map>
|
9
|
-
#include <fstream>
|
10
|
-
#include <iostream>
|
11
|
-
#include <assert.h>
|
12
|
-
#include "StringUtil.hpp"
|
13
|
-
|
14
|
-
namespace limonp {
|
15
|
-
|
16
|
-
using namespace std;
|
17
|
-
|
18
|
-
class Config {
|
19
|
-
public:
|
20
|
-
explicit Config(const string& filePath) {
|
21
|
-
LoadFile(filePath);
|
22
|
-
}
|
23
|
-
|
24
|
-
operator bool () {
|
25
|
-
return !map_.empty();
|
26
|
-
}
|
27
|
-
|
28
|
-
string Get(const string& key, const string& defaultvalue) const {
|
29
|
-
map<string, string>::const_iterator it = map_.find(key);
|
30
|
-
if(map_.end() != it) {
|
31
|
-
return it->second;
|
32
|
-
}
|
33
|
-
return defaultvalue;
|
34
|
-
}
|
35
|
-
int Get(const string& key, int defaultvalue) const {
|
36
|
-
string str = Get(key, "");
|
37
|
-
if("" == str) {
|
38
|
-
return defaultvalue;
|
39
|
-
}
|
40
|
-
return atoi(str.c_str());
|
41
|
-
}
|
42
|
-
const char* operator [] (const char* key) const {
|
43
|
-
if(NULL == key) {
|
44
|
-
return NULL;
|
45
|
-
}
|
46
|
-
map<string, string>::const_iterator it = map_.find(key);
|
47
|
-
if(map_.end() != it) {
|
48
|
-
return it->second.c_str();
|
49
|
-
}
|
50
|
-
return NULL;
|
51
|
-
}
|
52
|
-
|
53
|
-
string GetConfigInfo() const {
|
54
|
-
string res;
|
55
|
-
res << *this;
|
56
|
-
return res;
|
57
|
-
}
|
58
|
-
|
59
|
-
private:
|
60
|
-
void LoadFile(const string& filePath) {
|
61
|
-
ifstream ifs(filePath.c_str());
|
62
|
-
assert(ifs);
|
63
|
-
string line;
|
64
|
-
vector<string> vecBuf;
|
65
|
-
size_t lineno = 0;
|
66
|
-
while(getline(ifs, line)) {
|
67
|
-
lineno ++;
|
68
|
-
Trim(line);
|
69
|
-
if(line.empty() || StartsWith(line, "#")) {
|
70
|
-
continue;
|
71
|
-
}
|
72
|
-
vecBuf.clear();
|
73
|
-
Split(line, vecBuf, "=");
|
74
|
-
if(2 != vecBuf.size()) {
|
75
|
-
fprintf(stderr, "line[%s] illegal.\n", line.c_str());
|
76
|
-
assert(false);
|
77
|
-
continue;
|
78
|
-
}
|
79
|
-
string& key = vecBuf[0];
|
80
|
-
string& value = vecBuf[1];
|
81
|
-
Trim(key);
|
82
|
-
Trim(value);
|
83
|
-
if(!map_.insert(make_pair(key, value)).second) {
|
84
|
-
fprintf(stderr, "key[%s] already exits.\n", key.c_str());
|
85
|
-
assert(false);
|
86
|
-
continue;
|
87
|
-
}
|
88
|
-
}
|
89
|
-
ifs.close();
|
90
|
-
}
|
91
|
-
|
92
|
-
friend ostream& operator << (ostream& os, const Config& config);
|
93
|
-
|
94
|
-
map<string, string> map_;
|
95
|
-
}; // class Config
|
96
|
-
|
97
|
-
inline ostream& operator << (ostream& os, const Config& config) {
|
98
|
-
return os << config.map_;
|
99
|
-
}
|
100
|
-
|
101
|
-
} // namespace limonp
|
102
|
-
|
103
|
-
#endif // LIMONP_CONFIG_H
|
@@ -1,74 +0,0 @@
|
|
1
|
-
#ifndef LIMONP_FILELOCK_HPP
|
2
|
-
#define LIMONP_FILELOCK_HPP
|
3
|
-
|
4
|
-
#include <unistd.h>
|
5
|
-
#include <stdlib.h>
|
6
|
-
#include <stdio.h>
|
7
|
-
#include <fcntl.h>
|
8
|
-
#include <errno.h>
|
9
|
-
#include <string>
|
10
|
-
#include <string.h>
|
11
|
-
#include <assert.h>
|
12
|
-
|
13
|
-
namespace limonp {
|
14
|
-
|
15
|
-
using std::string;
|
16
|
-
|
17
|
-
class FileLock {
|
18
|
-
public:
|
19
|
-
FileLock() : fd_(-1), ok_(true) {
|
20
|
-
}
|
21
|
-
~FileLock() {
|
22
|
-
if(fd_ > 0) {
|
23
|
-
Close();
|
24
|
-
}
|
25
|
-
}
|
26
|
-
void Open(const string& fname) {
|
27
|
-
assert(fd_ == -1);
|
28
|
-
fd_ = open(fname.c_str(), O_RDWR | O_CREAT, 0644);
|
29
|
-
if(fd_ < 0) {
|
30
|
-
ok_ = false;
|
31
|
-
err_ = strerror(errno);
|
32
|
-
}
|
33
|
-
}
|
34
|
-
void Close() {
|
35
|
-
::close(fd_);
|
36
|
-
}
|
37
|
-
void Lock() {
|
38
|
-
if(LockOrUnlock(fd_, true) < 0) {
|
39
|
-
ok_ = false;
|
40
|
-
err_ = strerror(errno);
|
41
|
-
}
|
42
|
-
}
|
43
|
-
void UnLock() {
|
44
|
-
if(LockOrUnlock(fd_, false) < 0) {
|
45
|
-
ok_ = false;
|
46
|
-
err_ = strerror(errno);
|
47
|
-
}
|
48
|
-
}
|
49
|
-
bool Ok() const {
|
50
|
-
return ok_;
|
51
|
-
}
|
52
|
-
string Error() const {
|
53
|
-
return err_;
|
54
|
-
}
|
55
|
-
private:
|
56
|
-
static int LockOrUnlock(int fd, bool lock) {
|
57
|
-
errno = 0;
|
58
|
-
struct flock f;
|
59
|
-
memset(&f, 0, sizeof(f));
|
60
|
-
f.l_type = (lock ? F_WRLCK : F_UNLCK);
|
61
|
-
f.l_whence = SEEK_SET;
|
62
|
-
f.l_start = 0;
|
63
|
-
f.l_len = 0; // Lock/unlock entire file
|
64
|
-
return fcntl(fd, F_SETLK, &f);
|
65
|
-
}
|
66
|
-
|
67
|
-
int fd_;
|
68
|
-
bool ok_;
|
69
|
-
string err_;
|
70
|
-
}; // class FileLock
|
71
|
-
|
72
|
-
}// namespace limonp
|
73
|
-
|
74
|
-
#endif // LIMONP_FILELOCK_HPP
|
@@ -1,139 +0,0 @@
|
|
1
|
-
#ifndef LIMONP_LOCAL_VECTOR_HPP
|
2
|
-
#define LIMONP_LOCAL_VECTOR_HPP
|
3
|
-
|
4
|
-
#include <iostream>
|
5
|
-
#include <stdlib.h>
|
6
|
-
#include <assert.h>
|
7
|
-
#include <string.h>
|
8
|
-
|
9
|
-
namespace limonp {
|
10
|
-
using namespace std;
|
11
|
-
/*
|
12
|
-
* LocalVector<T> : T must be primitive type (char , int, size_t), if T is struct or class, LocalVector<T> may be dangerous..
|
13
|
-
* LocalVector<T> is simple and not well-tested.
|
14
|
-
*/
|
15
|
-
const size_t LOCAL_VECTOR_BUFFER_SIZE = 16;
|
16
|
-
template <class T>
|
17
|
-
class LocalVector {
|
18
|
-
public:
|
19
|
-
typedef const T* const_iterator ;
|
20
|
-
typedef T value_type;
|
21
|
-
typedef size_t size_type;
|
22
|
-
private:
|
23
|
-
T buffer_[LOCAL_VECTOR_BUFFER_SIZE];
|
24
|
-
T * ptr_;
|
25
|
-
size_t size_;
|
26
|
-
size_t capacity_;
|
27
|
-
public:
|
28
|
-
LocalVector() {
|
29
|
-
init_();
|
30
|
-
};
|
31
|
-
LocalVector(const LocalVector<T>& vec) {
|
32
|
-
init_();
|
33
|
-
*this = vec;
|
34
|
-
}
|
35
|
-
LocalVector(const_iterator begin, const_iterator end) { // TODO: make it faster
|
36
|
-
init_();
|
37
|
-
while(begin != end) {
|
38
|
-
push_back(*begin++);
|
39
|
-
}
|
40
|
-
}
|
41
|
-
LocalVector(size_t size, const T& t) { // TODO: make it faster
|
42
|
-
init_();
|
43
|
-
while(size--) {
|
44
|
-
push_back(t);
|
45
|
-
}
|
46
|
-
}
|
47
|
-
~LocalVector() {
|
48
|
-
if(ptr_ != buffer_) {
|
49
|
-
free(ptr_);
|
50
|
-
}
|
51
|
-
};
|
52
|
-
public:
|
53
|
-
LocalVector<T>& operator = (const LocalVector<T>& vec) {
|
54
|
-
clear();
|
55
|
-
size_ = vec.size();
|
56
|
-
capacity_ = vec.capacity();
|
57
|
-
if(vec.buffer_ == vec.ptr_) {
|
58
|
-
memcpy(buffer_, vec.buffer_, sizeof(T) * size_);
|
59
|
-
ptr_ = buffer_;
|
60
|
-
} else {
|
61
|
-
ptr_ = (T*) malloc(vec.capacity() * sizeof(T));
|
62
|
-
assert(ptr_);
|
63
|
-
memcpy(ptr_, vec.ptr_, vec.size() * sizeof(T));
|
64
|
-
}
|
65
|
-
return *this;
|
66
|
-
}
|
67
|
-
private:
|
68
|
-
void init_() {
|
69
|
-
ptr_ = buffer_;
|
70
|
-
size_ = 0;
|
71
|
-
capacity_ = LOCAL_VECTOR_BUFFER_SIZE;
|
72
|
-
}
|
73
|
-
public:
|
74
|
-
T& operator [] (size_t i) {
|
75
|
-
return ptr_[i];
|
76
|
-
}
|
77
|
-
const T& operator [] (size_t i) const {
|
78
|
-
return ptr_[i];
|
79
|
-
}
|
80
|
-
void push_back(const T& t) {
|
81
|
-
if(size_ == capacity_) {
|
82
|
-
assert(capacity_);
|
83
|
-
reserve(capacity_ * 2);
|
84
|
-
}
|
85
|
-
ptr_[size_ ++ ] = t;
|
86
|
-
}
|
87
|
-
void reserve(size_t size) {
|
88
|
-
if(size <= capacity_) {
|
89
|
-
return;
|
90
|
-
}
|
91
|
-
T * next = (T*)malloc(sizeof(T) * size);
|
92
|
-
assert(next);
|
93
|
-
T * old = ptr_;
|
94
|
-
ptr_ = next;
|
95
|
-
memcpy(ptr_, old, sizeof(T) * capacity_);
|
96
|
-
capacity_ = size;
|
97
|
-
if(old != buffer_) {
|
98
|
-
free(old);
|
99
|
-
}
|
100
|
-
}
|
101
|
-
bool empty() const {
|
102
|
-
return 0 == size();
|
103
|
-
}
|
104
|
-
size_t size() const {
|
105
|
-
return size_;
|
106
|
-
}
|
107
|
-
size_t capacity() const {
|
108
|
-
return capacity_;
|
109
|
-
}
|
110
|
-
const_iterator begin() const {
|
111
|
-
return ptr_;
|
112
|
-
}
|
113
|
-
const_iterator end() const {
|
114
|
-
return ptr_ + size_;
|
115
|
-
}
|
116
|
-
void clear() {
|
117
|
-
if(ptr_ != buffer_) {
|
118
|
-
free(ptr_);
|
119
|
-
}
|
120
|
-
init_();
|
121
|
-
}
|
122
|
-
};
|
123
|
-
|
124
|
-
template <class T>
|
125
|
-
ostream & operator << (ostream& os, const LocalVector<T>& vec) {
|
126
|
-
if(vec.empty()) {
|
127
|
-
return os << "[]";
|
128
|
-
}
|
129
|
-
os<<"[\""<<vec[0];
|
130
|
-
for(size_t i = 1; i < vec.size(); i++) {
|
131
|
-
os<<"\", \""<<vec[i];
|
132
|
-
}
|
133
|
-
os<<"\"]";
|
134
|
-
return os;
|
135
|
-
}
|
136
|
-
|
137
|
-
}
|
138
|
-
|
139
|
-
#endif
|
@@ -1,76 +0,0 @@
|
|
1
|
-
#ifndef LIMONP_LOGGING_HPP
|
2
|
-
#define LIMONP_LOGGING_HPP
|
3
|
-
|
4
|
-
#include <sstream>
|
5
|
-
#include <iostream>
|
6
|
-
#include <cassert>
|
7
|
-
#include <cstdlib>
|
8
|
-
#include <ctime>
|
9
|
-
|
10
|
-
#ifdef XLOG
|
11
|
-
#error "XLOG has been defined already"
|
12
|
-
#endif // XLOG
|
13
|
-
#ifdef XCHECK
|
14
|
-
#error "XCHECK has been defined already"
|
15
|
-
#endif // XCHECK
|
16
|
-
|
17
|
-
#define XLOG(level) limonp::Logger(limonp::LL_##level, __FILE__, __LINE__).Stream()
|
18
|
-
#define XCHECK(exp) if(!(exp)) XLOG(FATAL) << "exp: ["#exp << "] false. "
|
19
|
-
|
20
|
-
namespace limonp {
|
21
|
-
|
22
|
-
enum {
|
23
|
-
LL_DEBUG = 0,
|
24
|
-
LL_INFO = 1,
|
25
|
-
LL_WARNING = 2,
|
26
|
-
LL_ERROR = 3,
|
27
|
-
LL_FATAL = 4,
|
28
|
-
}; // enum
|
29
|
-
|
30
|
-
static const char * LOG_LEVEL_ARRAY[] = {"DEBUG","INFO","WARN","ERROR","FATAL"};
|
31
|
-
static const char * LOG_TIME_FORMAT = "%Y-%m-%d %H:%M:%S";
|
32
|
-
|
33
|
-
class Logger {
|
34
|
-
public:
|
35
|
-
Logger(size_t level, const char* filename, int lineno)
|
36
|
-
: level_(level) {
|
37
|
-
#ifdef LOGGING_LEVEL
|
38
|
-
if (level_ < LOGGING_LEVEL) {
|
39
|
-
return;
|
40
|
-
}
|
41
|
-
#endif
|
42
|
-
assert(level_ <= sizeof(LOG_LEVEL_ARRAY)/sizeof(*LOG_LEVEL_ARRAY));
|
43
|
-
char buf[32];
|
44
|
-
time_t now;
|
45
|
-
time(&now);
|
46
|
-
strftime(buf, sizeof(buf), LOG_TIME_FORMAT, localtime(&now));
|
47
|
-
stream_ << buf
|
48
|
-
<< " " << filename
|
49
|
-
<< ":" << lineno
|
50
|
-
<< " " << LOG_LEVEL_ARRAY[level_]
|
51
|
-
<< " ";
|
52
|
-
}
|
53
|
-
~Logger() {
|
54
|
-
#ifdef LOGGING_LEVEL
|
55
|
-
if (level_ < LOGGING_LEVEL) {
|
56
|
-
return;
|
57
|
-
}
|
58
|
-
#endif
|
59
|
-
std::cerr << stream_.str() << std::endl;
|
60
|
-
if (level_ == LL_FATAL) {
|
61
|
-
abort();
|
62
|
-
}
|
63
|
-
}
|
64
|
-
|
65
|
-
std::ostream& Stream() {
|
66
|
-
return stream_;
|
67
|
-
}
|
68
|
-
|
69
|
-
private:
|
70
|
-
std::ostringstream stream_;
|
71
|
-
size_t level_;
|
72
|
-
}; // class Logger
|
73
|
-
|
74
|
-
} // namespace limonp
|
75
|
-
|
76
|
-
#endif // LIMONP_LOGGING_HPP
|