mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 22:02:27 +00:00
Initial import
This commit is contained in:
commit
c91b3c5006
14915 changed files with 590219 additions and 0 deletions
33
libc/alg/reverse.h
Normal file
33
libc/alg/reverse.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_ALG_REVERSE_H_
|
||||
#define COSMOPOLITAN_LIBC_ALG_REVERSE_H_
|
||||
#include "libc/bits/xchg.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* Reverses array.
|
||||
*
|
||||
* @param ARRAY is a typed array or a pointer to one
|
||||
* @param COUNT is the number of items
|
||||
* @return pointer to start of array
|
||||
* @see ARRAYLEN()
|
||||
*/
|
||||
#endif
|
||||
#define reverse(ARRAY, COUNT) \
|
||||
({ \
|
||||
autotype(&(ARRAY)[0]) Array = (ARRAY); \
|
||||
size_t Count = (COUNT); \
|
||||
if (Count) { \
|
||||
size_t Start = 0; \
|
||||
size_t End = Count - 1; \
|
||||
while (Start < End) { \
|
||||
xchg(&Array[Start], &Array[End]); \
|
||||
++Start; \
|
||||
--End; \
|
||||
} \
|
||||
} \
|
||||
Array; \
|
||||
})
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_ALG_REVERSE_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue