-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBasic.h
95 lines (80 loc) · 2.61 KB
/
Basic.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
#ifndef _BASIC_H_
#define _BASIC_H_
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define MIN( a, b ) ( ( a ) < ( b ) ? ( a ) : ( b ) )
#define MAX( a, b ) ( ( a ) < ( b ) ? ( b ) : ( a ) )
#define SQR( a ) ( ( a ) * ( a ) )
#define PI 3.1415926535897932384
typedef std::set< int > IntSet;
typedef std::vector< int > IntVec;
typedef std::set< double > DoubleSet;
typedef std::vector< IntSet > SetVec;
typedef std::pair< int, int > IntPair;
typedef std::vector< IntPair > PairVec;
typedef std::map< int, IntSet > SetMap;
typedef std::vector< double > DoubleVec;
typedef std::vector< unsigned > UnsignedVec;
typedef std::vector< std::string > StringVec;
typedef std::pair< double, double > DoublePair;
// create a vector of integers from lo to (hi-1)
inline IntVec incvec( unsigned lo, unsigned hi ) {
IntVec out;
for ( unsigned i = lo; i < hi; ++i )
out.push_back( i );
return out;
}
// insert all elements of a collection into a stream
template < typename T >
std::ostream & insertAll( std::ostream & stream, const T & begin, const T & end ) {
T i = begin;
stream << "[";
if ( i != end ) stream << *( i++ );
while ( i != end ) stream << "," << *( i++ );
return stream << "]";
}
// insert a pair into a stream
template < typename T, typename U >
std::ostream & operator<<( std::ostream & stream, const std::pair< T, U > & p ) {
return stream << "(" << p.first << "," << p.second << ")";
}
// insert a list into a stream
template < typename T >
std::ostream & operator<<( std::ostream & stream, const std::list< T > & l ) {
return insertAll( stream, l.begin(), l.end() );
}
// insert a map into a stream
template < typename T, typename U >
std::ostream & operator<<( std::ostream & stream, const std::map< T, U > & m ) {
return insertAll( stream, m.begin(), m.end() );
}
// insert a multiset into a stream
template < typename T >
std::ostream & operator<<( std::ostream & stream, const std::multiset< T > & s ) {
return insertAll( stream, s.begin(), s.end() );
}
// insert a set into a stream
template < typename T >
std::ostream & operator<<( std::ostream & stream, const std::set< T > & s ) {
return insertAll( stream, s.begin(), s.end() );
}
// insert a vector into a stream
template < typename T >
std::ostream & operator<<( std::ostream & stream, const std::vector< T > &v ) {
return insertAll( stream, v.begin(), v.end() );
}
inline void tabindent( std::ostream & stream, unsigned indent ) {
for ( unsigned i = 0; i < indent; ++i )
stream << "\t";
}
#endif