[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
stdlib.h File Reference
#include <stddef.h>
Include dependency graph for stdlib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int atoi (const char *)
 
void qsort (void *array, size_t cnt, size_t size, int(*compare)(const void *, const void *))
 
void * bsearch (const void *key, const void *array, size_t cnt, size_t size, int(*compare)(const void *, const void *))
 
void sort (void *array, size_t cnt, size_t size, int(*compare)(const void *, const void *, void *aux), void *aux)
 
void * binary_search (const void *key, const void *array, size_t cnt, size_t size, int(*compare)(const void *, const void *, void *aux), void *aux)
 

Function Documentation

◆ atoi()

int atoi ( const char *  s)
11{
12 bool negative;
13 int value;
14
15 ASSERT (s != NULL);
16
17 /* Skip white space. */
18 while (isspace ((unsigned char) *s))
19 s++;
20
21 /* Parse sign. */
22 negative = false;
23 if (*s == '+')
24 s++;
25 else if (*s == '-')
26 {
27 negative = true;
28 s++;
29 }
30
31 /* Parse digits. We always initially parse the value as
32 negative, and then make it positive later, because the
33 negative range of an int is bigger than the positive range
34 on a 2's complement system. */
35 for (value = 0; isdigit (*s); s++)
36 value = value * 10 - (*s - '0');
37 if (!negative)
38 value = -value;
39
40 return value;
41}
static int isspace(int c)
Definition: ctype.h:12
static int isdigit(int c)
Definition: ctype.h:7
#define ASSERT(CONDITION)
Definition: debug.h:30
static uint8_t s[256]
Definition: random.c:17
#define NULL
Definition: stddef.h:4
Here is the call graph for this function:
Here is the caller graph for this function:

◆ binary_search()

void * binary_search ( const void *  key,
const void *  array,
size_t  cnt,
size_t  size,
int(*)(const void *, const void *, void *aux)  compare,
void *  aux 
)
188{
189 const unsigned char *first = array;
190 const unsigned char *last = array + size * cnt;
191
192 while (first < last)
193 {
194 size_t range = (last - first) / size;
195 const unsigned char *middle = first + (range / 2) * size;
196 int cmp = compare (key, middle, aux);
197
198 if (cmp < 0)
199 last = middle;
200 else if (cmp > 0)
201 first = middle + size;
202 else
203 return (void *) middle;
204 }
205
206 return NULL;
207}
uint16_t size
Definition: mmu.h:0
Here is the caller graph for this function:

◆ bsearch()

void * bsearch ( const void *  key,
const void *  array,
size_t  cnt,
size_t  size,
int(*)(const void *, const void *)  compare 
)
168{
169 return binary_search (key, array, cnt, size, compare_thunk, &compare);
170}
void * binary_search(const void *key, const void *array, size_t cnt, size_t size, int(*compare)(const void *, const void *, void *aux), void *aux)
Definition: stdlib.c:185
static int compare_thunk(const void *a, const void *b, void *aux)
Definition: stdlib.c:45
Here is the call graph for this function:

◆ qsort()

void qsort ( void *  array,
size_t  cnt,
size_t  size,
int(*)(const void *, const void *)  compare 
)
60{
61 sort (array, cnt, size, compare_thunk, &compare);
62}
void sort(void *array, size_t cnt, size_t size, int(*compare)(const void *, const void *, void *aux), void *aux)
Definition: stdlib.c:132
Here is the call graph for this function:

◆ sort()

void sort ( void *  array,
size_t  cnt,
size_t  size,
int(*)(const void *, const void *, void *aux)  compare,
void *  aux 
)
135{
136 size_t i;
137
138 ASSERT (array != NULL || cnt == 0);
139 ASSERT (compare != NULL);
140 ASSERT (size > 0);
141
142 /* Build a heap. */
143 for (i = cnt / 2; i > 0; i--)
144 heapify (array, i, cnt, size, compare, aux);
145
146 /* Sort the heap. */
147 for (i = cnt; i > 1; i--)
148 {
149 do_swap (array, 1, i, size);
150 heapify (array, 1, i - 1, size, compare, aux);
151 }
152}
static void heapify(unsigned char *array, size_t i, size_t cnt, size_t size, int(*compare)(const void *, const void *, void *aux), void *aux)
Definition: stdlib.c:97
static void do_swap(unsigned char *array, size_t a_idx, size_t b_idx, size_t size)
Definition: stdlib.c:67
Here is the call graph for this function:
Here is the caller graph for this function: