-
Notifications
You must be signed in to change notification settings - Fork 220
/
common.h
148 lines (122 loc) · 3.84 KB
/
common.h
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
146
147
/*
This file is part of VK/KittenPHP-DB-Engine.
VK/KittenPHP-DB-Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
VK/KittenPHP-DB-Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with VK/KittenPHP-DB-Engine. If not, see <http://www.gnu.org/licenses/>.
This program is released under the GPL with the additional exemption
that compiling, linking, and/or using OpenSSL is allowed.
You are free to remove this exemption from derived works.
Copyright 2012-2013 Vkontakte Ltd
2012-2013 Arseny Smirnov
2012-2013 Aliaksei Levin
*/
#pragma once
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <sstream>
#include <typeinfo>
#include <tr1/memory>
#include <mcheck.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include "dl-utils-lite.h"
#include "common-php-functions.h"
size_t total_mem_used __attribute__ ((weak));
template <class T, class TrackType, class BaseAllocator = std::allocator <T> >
class TrackerAllocator : public BaseAllocator {
public:
typedef typename BaseAllocator::pointer pointer;
typedef typename BaseAllocator::size_type size_type;
TrackerAllocator() throw()
: BaseAllocator() {
}
TrackerAllocator (const TrackerAllocator& b) throw()
: BaseAllocator (b) {
}
template <class U>
TrackerAllocator (const typename TrackerAllocator::template rebind <U>::other& b) throw()
: BaseAllocator (b) {
}
~TrackerAllocator() {
}
template <class U> struct rebind {
typedef TrackerAllocator <U, TrackType, typename BaseAllocator::template rebind <U>::other> other;
};
pointer allocate (size_type n) {
pointer r = BaseAllocator::allocate (n);
total_mem_used += n;
return r;
}
pointer allocate (size_type n, pointer h) {
pointer r = BaseAllocator::allocate (n, h);
total_mem_used += n;
return r;
}
void deallocate (pointer p, size_type n) throw() {
BaseAllocator::deallocate (p, n);
total_mem_used -= n;
}
};
//typedef std::basic_string <char,
//std::char_traits<char>,
//TrackerAllocator<char, std::string> > string;
//typedef std::vector<int,
//TrackerAllocator<int, std::vector<int> > > trackvector;
using std::vector;
using std::cerr;
using std::endl;
using std::map;
using std::set;
using std::tr1::shared_ptr;
using std::pair;
using std::queue;
using std::pair;
using std::make_pair;
using std::stringstream;
using std::string;
using std::swap;
using std::max;
using std::min;
#define DL_ADD_SUFF_(A, B) A##_##B
#define DL_ADD_SUFF(A, B) DL_ADD_SUFF_(A, B)
#define DL_CAT_(A, B) A##B
#define DL_CAT(A, B) DL_CAT_(A, B)
#define DL_STR(A) DL_STR_(A)
#define DL_STR_(A) # A
#define DL_EMPTY(A...)
#define DISALLOW_COPY_AND_ASSIGN(type_name) \
type_name (const type_name&); \
void operator = (const type_name&);
bool use_safe_integer_arithmetic __attribute__ ((weak)) = false;
inline int hash (const string &s) {
int res = 31;
for (int i = 0; i < (int)s.size(); i++) {
res = res * 239 + s[i];
}
res &= ~((unsigned)1 << 31);
return res;
}
inline unsigned long long hash_ll (const string &s) {
unsigned long long res = 31;
for (int i = 0; i < (int)s.size(); i++) {
res = res * 239 + s[i];
}
return res;
}