File: sequence.c

package info (click to toggle)
boost-jam 3.1.10-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,004 kB
  • ctags: 1,703
  • sloc: ansic: 11,378; yacc: 456; sh: 192; makefile: 43
file content (39 lines) | stat: -rw-r--r-- 1,016 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

#include "../native.h"

# ifndef max
# define max( a,b ) ((a)>(b)?(a):(b))
# endif


LIST *sequence_select_highest_ranked( PARSE *parse, FRAME *frame )
{
   /* Returns all of 'elements' for which corresponding element in parallel */
   /* list 'rank' is equal to the maximum value in 'rank'.                  */

    LIST* elements = lol_get( frame->args, 0 );    
    LIST* rank = lol_get( frame->args, 1 );    
    
    LIST* result = 0;
    LIST* tmp;
    int highest_rank = -1;

    for (tmp = rank; tmp; tmp = tmp->next)
        highest_rank = max(highest_rank, atoi(tmp->string));

    for (; rank; rank = rank->next, elements = elements->next)
        if (atoi(rank->string) == highest_rank)
            result = list_new(result, elements->string);

    return result;
}

void init_sequence()
{
    {
        char* args[] = { "elements", "*", ":", "rank", "*", 0 };
        declare_native_rule("sequence", "select-highest-ranked", args, 
                            sequence_select_highest_ranked);
    }

}