Skip to content

Commit

Permalink
Fixes to shuffle Array slice_
Browse files Browse the repository at this point in the history
  • Loading branch information
aslze committed Nov 13, 2022
1 parent 9cd21ba commit a257170
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
3 changes: 2 additions & 1 deletion include/asl/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class Array
T* operator->() {return &(a[i]);}
operator bool() const {return i < j;}
T& operator[](int k) {return a[i+k];}
const T& operator[](int k) const {return a[i+k];}
T& operator[](int k) const {return a[i+k];}
int length() const {return j-i;}
};
int r() {return d().rc;}
Expand Down Expand Up @@ -603,6 +603,7 @@ class Array
Enumerator all() {return Enumerator(*this);}
Enumerator all() const {return Enumerator(*this);}
Enumerator slice_(int i, int j=0) {if(j==0) j=length();return Enumerator(*this, i, j);}
Enumerator slice_(int i, int j = 0) const {if(j==0) j=length();return Enumerator(*this, i, j);}
};

typedef Array<byte> ByteArray;
Expand Down
36 changes: 24 additions & 12 deletions include/asl/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,24 @@ inline T rad2deg(T x) {return (T)(x*57.29577951308232);}

static const double PI = 3.14159265358979323;

template<class T>
inline void vswap(T& a, T& b)
{
T A = a;
a = b;
b = A;
}

template<class T>
inline void swap(T& a, T& b)
{
char t[sizeof(T)];
memcpy(t, &a, sizeof(T));
memcpy(&a, &b, sizeof(T));
memcpy(&b, t, sizeof(T));
}


/**
Endianness types for binary parsing/writing
*/
Expand Down Expand Up @@ -295,6 +313,12 @@ class ASL_API Random
*/
template <typename E>
void shuffle(E& a) { shuffle(&a[0], a.length()); }

/**
Shuffles an array of elements in place.
*/
template<typename E>
void shuffle(const E& a) { shuffle(&a[0], a.length()); }
};

extern ASL_API Random random; //!< A global random number generator
Expand Down Expand Up @@ -354,18 +378,6 @@ inline T max(T a, T b) {if(a>b) return a; else return b;}
template <class T>
inline T min(T a, T b) {if(a<b) return a; else return b;}

template <class T>
inline void vswap(T& a, T& b) {T A=a; a=b; b=A;}

template <class T>
inline void swap(T& a, T& b)
{
char t[sizeof(T)];
memcpy(t, &a, sizeof(T));
memcpy(&a, &b, sizeof(T));
memcpy(&b, t, sizeof(T));
}

}

inline void* operator new (size_t, int* p) { return p; }
Expand Down

0 comments on commit a257170

Please sign in to comment.