Skip to content

Commit

Permalink
[6_7] c++98 by default, c++11 for mingw, c++17 for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
da-liii authored Aug 5, 2023
1 parent 133b94e commit 69ebde6
Show file tree
Hide file tree
Showing 23 changed files with 114 additions and 105 deletions.
3 changes: 2 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Standard: Cpp03
SpaceBeforeAssignmentOperators: false
SpaceBeforeParens: Always
AlwaysBreakAfterReturnType: TopLevelDefinitions
Expand All @@ -10,4 +11,4 @@ BreakBeforeBraces: Custom
BraceWrapping:
BeforeElse: true
PointerAlignment: Left
CommentPragmas: '^\\.+'
CommentPragmas: '^\\.+'
8 changes: 4 additions & 4 deletions Data/String/fast_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ string_searcher_rep::string_searcher_rep (string s2) : s (s2), a () {
codes[i]= (int) (unsigned int) (unsigned char) s[i];
int l= 1;
while (l <= n) {
hashmap<int, array<int>> h;
hashmap<int, array<int> > h;
for (i= 0; i + l <= n; i++) {
int c= codes[i];
if (!h->contains (c)) h (c)= array<int> ();
Expand Down Expand Up @@ -129,9 +129,9 @@ get_longest_common (string s1, string s2, int& b1, int& e1, int& b2, int& e2) {
string_searcher ss1 (s1);
string_searcher ss2 (s2);
for (int i= min (N (ss1->a), N (ss2->a)) - 1; i >= 0; i--) {
hashmap<int, array<int>> a1= ss1->a[i];
hashmap<int, array<int>> a2= ss2->a[i];
iterator<int> it= iterate (a1);
hashmap<int, array<int> > a1= ss1->a[i];
hashmap<int, array<int> > a2= ss2->a[i];
iterator<int> it= iterate (a1);
while (it->busy ()) {
int h = it->next ();
array<int> ps1= a1[h];
Expand Down
6 changes: 3 additions & 3 deletions Data/String/fast_search.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

class string_searcher;
class string_searcher_rep : concrete_struct {
string s;
array<hashmap<int, array<int>>> a;
array<int> search_sub (string what);
string s;
array<hashmap<int, array<int> > > a;
array<int> search_sub (string what);

public:
string_searcher_rep (string s);
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Abstractions/blackbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type_box (blackbox bb) {
template <class T>
blackbox
close_box (const T& data) {
return tm_new<whitebox_rep<T>> (data);
return tm_new<whitebox_rep<T> > (data);
}

template <class T>
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Algorithms/merge_sort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ merge_sort_leq (array<T>& a) {
template <class T>
inline void
merge_sort (array<T>& a) {
merge_sort_leq<T, less_eq_operator<T>> (a);
merge_sort_leq<T, less_eq_operator<T> > (a);
}

/******************************************************************************
Expand Down Expand Up @@ -127,7 +127,7 @@ merge_sort_leq_permutation (array<T>& a) {
template <class T>
array<int>
merge_sort_leq_permutation (array<T>& a) {
return merge_sort_leq_permutation<T, less_eq_operator<T>> (a);
return merge_sort_leq_permutation<T, less_eq_operator<T> > (a);
}

template <class T>
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Containers/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ template <class T> class array {
/**
* @brief Construct a new array object with length 0.
*/
inline array (int n= 0) : rep (tm_new<array_rep<T>> (n)) {}
inline array (int n= 0) : rep (tm_new<array_rep<T> > (n)) {}

/**
* @brief Construct a new array object from a C array with specified length.
Expand Down
10 changes: 5 additions & 5 deletions Kernel/Containers/array.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,34 @@ array_rep<T>::resize (int m) {

template <class T> array<T>::array (T* a, int n) {
int i;
rep= tm_new<array_rep<T>> (n);
rep= tm_new<array_rep<T> > (n);
for (i= 0; i < n; i++)
rep->a[i]= a[i];
}

template <class T> array<T>::array (T x1, T x2) {
rep = tm_new<array_rep<T>> (2);
rep = tm_new<array_rep<T> > (2);
rep->a[0]= x1;
rep->a[1]= x2;
}

template <class T> array<T>::array (T x1, T x2, T x3) {
rep = tm_new<array_rep<T>> (3);
rep = tm_new<array_rep<T> > (3);
rep->a[0]= x1;
rep->a[1]= x2;
rep->a[2]= x3;
}

template <class T> array<T>::array (T x1, T x2, T x3, T x4) {
rep = tm_new<array_rep<T>> (4);
rep = tm_new<array_rep<T> > (4);
rep->a[0]= x1;
rep->a[1]= x2;
rep->a[2]= x3;
rep->a[3]= x4;
}

template <class T> array<T>::array (T x1, T x2, T x3, T x4, T x5) {
rep = tm_new<array_rep<T>> (5);
rep = tm_new<array_rep<T> > (5);
rep->a[0]= x1;
rep->a[1]= x2;
rep->a[2]= x3;
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Containers/hashfunc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ template <class T, class U> class hashfunc {
* @param init The initial value for the hash map.
*/
inline hashfunc (U (*func) (T), U init)
: rep (tm_new<hashfunc_rep<T, U>> (func, init)) {}
: rep (tm_new<hashfunc_rep<T, U> > (func, init)) {}

/**
* @brief Applies the hash function to the given input.
Expand Down
16 changes: 8 additions & 8 deletions Kernel/Containers/hashmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ template <class T, class U> struct hashentry {
};

template <class T, class U> class hashmap_rep : concrete_struct {
int size; // size of hashmap (nr of entries)
int n; // nr of keys (a power of two)
int max; // mean number of entries per key
U init; // default entry
list<hashentry<T, U>>* a; // the array of entries
int size; // size of hashmap (nr of entries)
int n; // nr of keys (a power of two)
int max; // mean number of entries per key
U init; // default entry
list<hashentry<T, U> >* a; // the array of entries

public:
inline hashmap_rep<T, U> (U init2, int n2= 1, int max2= 1)
: size (0), n (n2), max (max2), init (init2),
a (tm_new_array<list<hashentry<T, U>>> (n)) {}
a (tm_new_array<list<hashentry<T, U> > > (n)) {}
inline ~hashmap_rep<T, U> () { tm_delete_array (a); }
void resize (int n);
void reset (T x);
Expand Down Expand Up @@ -88,9 +88,9 @@ template <class T, class U> class hashmap {
CONCRETE_TEMPLATE_2 (hashmap, T, U);
static hashmap<T, U> init;
inline hashmap ()
: rep (tm_new<hashmap_rep<T, U>> (type_helper<U>::init_val (), 1, 1)) {}
: rep (tm_new<hashmap_rep<T, U> > (type_helper<U>::init_val (), 1, 1)) {}
inline hashmap (U init, int n= 1, int max= 1)
: rep (tm_new<hashmap_rep<T, U>> (init, n, max)) {}
: rep (tm_new<hashmap_rep<T, U> > (init, n, max)) {}
inline U operator[] (T x) { return rep->bracket_ro (x); }
inline U& operator() (T x) { return rep->bracket_rw (x); }
};
Expand Down
46 changes: 23 additions & 23 deletions Kernel/Containers/hashmap.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,26 @@ operator!= (H h1, H h2) {

TMPL void
hashmap_rep<T, U>::resize (int n2) {
int i;
int oldn= n;
list<hashentry<T, U>>* olda= a;
n = n2;
a = tm_new_array<list<hashentry<T, U>>> (n);
int i;
int oldn= n;
list<hashentry<T, U> >* olda= a;
n = n2;
a = tm_new_array<list<hashentry<T, U> > > (n);
for (i= 0; i < oldn; i++) {
list<hashentry<T, U>> l (olda[i]);
list<hashentry<T, U> > l (olda[i]);
while (!is_nil (l)) {
list<hashentry<T, U>>& newl= a[hash (l->item.key) & (n - 1)];
newl = list<hashentry<T, U>> (l->item, newl);
l = l->next;
list<hashentry<T, U> >& newl= a[hash (l->item.key) & (n - 1)];
newl = list<hashentry<T, U> > (l->item, newl);
l = l->next;
}
}
tm_delete_array (olda);
}

TMPL bool
hashmap_rep<T, U>::contains (T x) {
int hv= hash (x);
list<hashentry<T, U>> l (a[hv & (n - 1)]);
int hv= hash (x);
list<hashentry<T, U> > l (a[hv & (n - 1)]);
while (!is_nil (l)) {
if (l->item.code == hv && l->item.key == x) return true;
l= l->next;
Expand All @@ -80,23 +80,23 @@ hashmap_rep<T, U>::empty () {

TMPL U&
hashmap_rep<T, U>::bracket_rw (T x) {
int hv= hash (x);
list<hashentry<T, U>> l (a[hv & (n - 1)]);
int hv= hash (x);
list<hashentry<T, U> > l (a[hv & (n - 1)]);
while (!is_nil (l)) {
if (l->item.code == hv && l->item.key == x) return l->item.im;
l= l->next;
}
if (size >= n * max) resize (n << 1);
list<hashentry<T, U>>& rl= a[hv & (n - 1)];
rl = list<hashentry<T, U>> (H (hv, x, init), rl);
list<hashentry<T, U> >& rl= a[hv & (n - 1)];
rl = list<hashentry<T, U> > (H (hv, x, init), rl);
size++;
return rl->item.im;
}

TMPL U
hashmap_rep<T, U>::bracket_ro (T x) {
int hv= hash (x);
list<hashentry<T, U>> l (a[hv & (n - 1)]);
int hv= hash (x);
list<hashentry<T, U> > l (a[hv & (n - 1)]);
while (!is_nil (l)) {
if (l->item.code == hv && l->item.key == x) return l->item.im;
l= l->next;
Expand All @@ -106,8 +106,8 @@ hashmap_rep<T, U>::bracket_ro (T x) {

TMPL void
hashmap_rep<T, U>::reset (T x) {
int hv= hash (x);
list<hashentry<T, U>>* l = &(a[hv & (n - 1)]);
int hv= hash (x);
list<hashentry<T, U> >* l = &(a[hv & (n - 1)]);
while (!is_nil (*l)) {
if ((*l)->item.code == hv && (*l)->item.key == x) {
*l= (*l)->next;
Expand All @@ -123,7 +123,7 @@ TMPL void
hashmap_rep<T, U>::generate (void (*routine) (T)) {
int i;
for (i= 0; i < n; i++) {
list<hashentry<T, U>> l (a[i]);
list<hashentry<T, U> > l (a[i]);
while (!is_nil (l)) {
routine (l->item.key);
l= l->next;
Expand All @@ -136,7 +136,7 @@ operator<< (tm_ostream& out, hashmap<T, U> h) {
int i= 0, j= 0, n= h->n, size= h->size;
out << "{ ";
for (; i < n; i++) {
list<hashentry<T, U>> l= h->a[i];
list<hashentry<T, U> > l= h->a[i];
for (; !is_nil (l); l= l->next, j++) {
out << l->item;
if (j != size - 1) out << ", ";
Expand All @@ -150,7 +150,7 @@ TMPL void
hashmap_rep<T, U>::join (hashmap<T, U> h) {
int i= 0, n= h->n;
for (; i < n; i++) {
list<hashentry<T, U>> l= h->a[i];
list<hashentry<T, U> > l= h->a[i];
for (; !is_nil (l); l= l->next)
bracket_rw (l->item.key)= copy (l->item.im);
}
Expand All @@ -161,7 +161,7 @@ operator== (hashmap<T, U> h1, hashmap<T, U> h2) {
if (h1->size != h2->size) return false;
int i= 0, n= h1->n;
for (; i < n; i++) {
list<hashentry<T, U>> l= h1->a[i];
list<hashentry<T, U> > l= h1->a[i];
for (; !is_nil (l); l= l->next)
if (h2[l->item.key] != l->item.im) return false;
}
Expand Down
24 changes: 12 additions & 12 deletions Kernel/Containers/hashmap_extra.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@

TMPL void
hashmap_rep<T, U>::write_back (T x, hashmap<T, U> base) {
int hv= hash (x);
list<hashentry<T, U>> l (a[hv & (n - 1)]);
int hv= hash (x);
list<hashentry<T, U> > l (a[hv & (n - 1)]);
while (!is_nil (l)) {
if (l->item.code == hv && l->item.key == x) return;
l= l->next;
}
if (size >= n * max) resize (n << 1);
list<hashentry<T, U>>& rl= a[hv & (n - 1)];
rl = list<hashentry<T, U>> (H (hv, x, init), rl);
list<hashentry<T, U> >& rl= a[hv & (n - 1)];
rl = list<hashentry<T, U> > (H (hv, x, init), rl);
size++;

list<hashentry<T, U>> bl (base->a[hv & (base->n - 1)]);
list<hashentry<T, U> > bl (base->a[hv & (base->n - 1)]);
while (!is_nil (bl)) {
if (bl->item.code == hv && bl->item.key == x) {
rl->item.im= bl->item.im;
Expand All @@ -44,7 +44,7 @@ TMPL void
hashmap_rep<T, U>::pre_patch (hashmap<T, U> patch, hashmap<T, U> base) {
int i= 0, n= patch->n;
for (; i < n; i++) {
list<hashentry<T, U>> l= patch->a[i];
list<hashentry<T, U> > l= patch->a[i];
for (; !is_nil (l); l= l->next) {
T x= l->item.key;
U y= contains (x) ? bracket_ro (x) : l->item.im;
Expand All @@ -58,7 +58,7 @@ TMPL void
hashmap_rep<T, U>::post_patch (hashmap<T, U> patch, hashmap<T, U> base) {
int i= 0, n= patch->n;
for (; i < n; i++) {
list<hashentry<T, U>> l= patch->a[i];
list<hashentry<T, U> > l= patch->a[i];
for (; !is_nil (l); l= l->next) {
T x= l->item.key;
U y= l->item.im;
Expand All @@ -68,11 +68,11 @@ hashmap_rep<T, U>::post_patch (hashmap<T, U> patch, hashmap<T, U> base) {
}
}

TMPL list<hashentry<T, U>>
copy_list (list<hashentry<T, U>> l) {
TMPL list<hashentry<T, U> >
copy_list (list<hashentry<T, U> > l) {
if (is_nil (l)) return l;
else
return list<hashentry<T, U>> (
return list<hashentry<T, U> > (
hashentry<T, U> (l->item.code, l->item.key, l->item.im),
copy_list (l->next));
}
Expand All @@ -92,7 +92,7 @@ TMPL hashmap<T, U>
int i;
hashmap<T, U> h (base->init);
for (i= 0; i < patch->n; i++) {
list<hashentry<T, U>> l (patch->a[i]);
list<hashentry<T, U> > l (patch->a[i]);
while (!is_nil (l)) {
if (l->item.im != base[l->item.key]) h (l->item.key)= l->item.im;
l= l->next;
Expand All @@ -106,7 +106,7 @@ TMPL hashmap<T, U>
int i;
hashmap<T, U> h (base->init);
for (i= 0; i < patch->n; i++) {
list<hashentry<T, U>> l (patch->a[i]);
list<hashentry<T, U> > l (patch->a[i]);
while (!is_nil (l)) {
if (l->item.im != base[l->item.key]) h (l->item.key)= base[l->item.key];
l= l->next;
Expand Down
6 changes: 3 additions & 3 deletions Kernel/Containers/hashset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ template <class T> class hashset_rep : concrete_struct {
*
*/
inline hashset_rep ()
: size (0), n (1), max (1), a (tm_new_array<list<T>> (1)) {}
: size (0), n (1), max (1), a (tm_new_array<list<T> > (1)) {}

/**
* @brief Construct a new hashset_rep object with specified values.
Expand All @@ -44,7 +44,7 @@ template <class T> class hashset_rep : concrete_struct {
* @param max2 The mean number of entries per key.
*/
inline hashset_rep (int n2, int max2= 1)
: size (0), n (n2), max (max2), a (tm_new_array<list<T>> (n)) {}
: size (0), n (n2), max (max2), a (tm_new_array<list<T> > (n)) {}

/**
* @brief Destroy the hashset_rep object.
Expand Down Expand Up @@ -79,7 +79,7 @@ template <class T> class hashset {
* @param max The mean number of entries per key.
*/
inline hashset (int n= 1, int max= 1)
: rep (tm_new<hashset_rep<T>> (n, max)) {}
: rep (tm_new<hashset_rep<T> > (n, max)) {}
};
CONCRETE_TEMPLATE_CODE (hashset, class, T);

Expand Down
2 changes: 1 addition & 1 deletion Kernel/Containers/hashset.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ hashset_rep<T>::resize (int n2) {
int oldn= n;
list<T>* olda= a;
n = n2;
a = tm_new_array<list<T>> (n);
a = tm_new_array<list<T> > (n);
for (i= 0; i < oldn; i++) {
list<T> l (olda[i]);
while (!is_nil (l)) {
Expand Down
Loading

0 comments on commit 69ebde6

Please sign in to comment.