/keyword_list.c (d636828dba2bc4ff3c5648900fb7ef8abf7f1f7e) (3200 bytes) (mode 100644) (type blob)
#ifndef CGPERF_KEYWORD_LIST_C
#define CGPERF_KEYWORD_LIST_C
#include <stdlib.h>
#include "keyword.h"
#include "keyword_list.h"
/*------------------------------------------------------------------------------------------------*/
#include "namespace/keyword.h"
#include "namespace/keyword_list.h"
/*------------------------------------------------------------------------------------------------*/
/*{{{ kwl_new */
static struct Keyword_List *kwl_new(struct Keyword *kw)
{
struct Keyword_List *t;
t = calloc(1, sizeof(*t));
t->kw = kw;
return t;
}/*}}}*/
/*{{{ kwextl_del */
static void kwl_del(struct Keyword_List *t)
{
free(t);
}/*}}}*/
/*{{{ delete_list */
static void delete_list(struct Keyword_List *list)
{
loop {
struct Keyword_List *next;
if (list == 0)
break;
next = list->next;
kwl_del(list);
list = next;
}
}/*}}}*/
/*{{{ copy_list_ext */
static struct Keyword_List *copy_list(struct Keyword_List *list)
{
struct Keyword_List *result;
struct Keyword_List **lastp;
lastp = &result;
loop {
struct Keyword_List *new_cons;
if (list == 0)
break;
new_cons = kwl_new(list->kw);
*lastp = new_cons;
lastp = &new_cons->next;
list = list->next;
}
*lastp = 0;
return result;
}/*}}}*/
/*{{{ mergesort_list */
/*
* Sorts a linear list, given a comparison function.
* Note: This uses a variant of mergesort that is *not* a stable sorting algorithm.
*/
static struct Keyword_List *mergesort_list(struct Keyword_List *list, bool (*less)(
struct Keyword *kw1, struct Keyword *kw2))
{
struct Keyword_List *middle;
struct Keyword_List *tmp;
struct Keyword_List *right_half;
if (list == 0 || list->next == 0)
/* List of length 0 or 1. Nothing to do. */
return list;
middle = list;
tmp = list->next;
loop {
tmp = tmp->next;
if (tmp == 0)
break;
tmp = tmp->next;
middle = middle->next;;
if (tmp == 0)
break;
}
/*
* Cut the list into two halves.
* If the list has n elements, the left half has ceiling(n/2) elements and the right half
* has floor(n/2) elements.
*/
right_half = middle->next;
middle->next = 0;
return merge(mergesort_list(list, less), mergesort_list(right_half, less), less);
}/*}}}*/
/*{{{ merge */
static struct Keyword_List *merge(struct Keyword_List *list1, struct Keyword_List *list2, bool
(*less)(struct Keyword *kw1, struct Keyword *kw2))
{
struct Keyword_List *result;
struct Keyword_List **resultp;
resultp = &result;
loop {
if (list1 == 0) {
*resultp = list2;
break;
}
if (list2 == 0) {
*resultp = list1;
break;
}
if (less(list2->kw, list1->kw)) {
*resultp = list2;
resultp = &list2->next;
/*
* We would have a stable sorting if the next line would read: list2 =
* *resultp;
*/
list2 = list1;
list2 = *resultp;
} else {
*resultp = list1;
resultp = &list1->next;
list1 = *resultp;
}
}
return result;
}/*}}}*/
/*------------------------------------------------------------------------------------------------*/
#define EPILOG
#include "namespace/keyword.h"
#include "namespace/keyword_list.h"
#undef EPILOG
/*------------------------------------------------------------------------------------------------*/
#endif
Mode |
Type |
Size |
Ref |
File |
100644 |
blob |
155 |
5b72180098c039db31d1ae3f9cfa9b58038c39e5 |
ABBREVIATIONS |
100644 |
blob |
252 |
82ea1f80bd08bdd20ebf6ff339ac4c1e6963cf54 |
CODING_STYLE |
100644 |
blob |
988 |
84b1a929903fafdfa1b89637d27f1be78091b254 |
README |
100644 |
blob |
255 |
77a9cbb244b51c8ea7271d40680e140fb61d677b |
all.c |
100644 |
blob |
2469 |
88f3c5a85178081ba8ed82cbe444e70364e8f9ac |
bool-array.c |
100644 |
blob |
1301 |
95585899ef9fa01219bb820a0fdb5bf3730d29dc |
bool-array.h |
100644 |
blob |
322 |
a581cb0d698cf4fad768d2e1d76eba8cd95ba620 |
c_fixing.h |
100644 |
blob |
2830 |
cae84c9e018be62e402986d84220972bc44faeda |
getline.c |
100644 |
blob |
803 |
3b2e9fe0fa2789429259320710193649abd8ca6c |
getline.h |
100644 |
blob |
587 |
0e9eb2b35a227500f1457e9ea4c4c0a2765f69e8 |
globals.h |
100644 |
blob |
131227 |
0b67e08b78e02b65a5b85ab33ed9d411ef89b0b0 |
gperf.pdf |
100644 |
blob |
4233 |
2df4f0b49d9c139852619af6380646847bcfaf90 |
hash-table.c |
100644 |
blob |
1637 |
1fb95e378dd619343f3b567687f63d506b8c13bc |
hash-table.h |
100644 |
blob |
980 |
74114adae41af5c48ce02167a9b408a6f1d7d1a0 |
hash.c |
100644 |
blob |
603 |
add7a1a544500039e13f99a1991e0b8a520dc7e5 |
hash.h |
100644 |
blob |
26629 |
a6784a05e9fce47bb13e9e80edcbed10cde77887 |
input.c |
100644 |
blob |
1785 |
1e14807e92c19ea7c276f137e13ac43a887142b4 |
input.h |
100644 |
blob |
4420 |
d7caf4e40dfebcc70161aaa8726586fb03e37ad9 |
keyword.c |
100644 |
blob |
2859 |
b4cbb4e55cbb4b30581207239cdb60deb29e3bed |
keyword.h |
100644 |
blob |
3200 |
d636828dba2bc4ff3c5648900fb7ef8abf7f1f7e |
keyword_list.c |
100644 |
blob |
1493 |
8ab44833fa65bd37719bf3bd6ba994e3325bb7de |
keyword_list.h |
100644 |
blob |
3490 |
a61204584054c59319978812df6869053e98e0f6 |
main.c |
040000 |
tree |
- |
2601d6e758839cb006901fccd9ef537fce13fa3a |
namespace |
100644 |
blob |
35946 |
1fb9da336b25695c248aacf3fb0079febf132bd0 |
options.c |
100644 |
blob |
6711 |
b7853ef0ce8248e2c4cd5a6349ab586201d56368 |
options.h |
100644 |
blob |
57175 |
ce761176a0e5830285d4ef3a585a01816daa579b |
output.c |
100644 |
blob |
4046 |
f0221f3f84539c2fec2f5f68df98f094c145a46e |
output.h |
100644 |
blob |
7272 |
84b2564a5a66f586f89d14e6ff09859161f24f3c |
positions.c |
100644 |
blob |
3699 |
7e1698c33ca484879b5a3454c8d9001d5cdaaaa9 |
positions.h |
100644 |
blob |
55266 |
294deac764f48ec12c61f9c5fa25d50b5863011b |
search.c |
100644 |
blob |
4728 |
2356686527da4e82877472c2b3d75d16f21dec72 |
search.h |
040000 |
tree |
- |
7e446953294cddd2cc0ff66ec0cd1b1654b4c85c |
tests |
100644 |
blob |
99 |
e4da099bacd7a88eeb2db964715d6574fc7fa81e |
version.h |
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/sylware/cgperf
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/sylware/cgperf
Clone this repository using git:
git clone git://git.rocketgit.com/user/sylware/cgperf
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main