#include #include #include #include #include "prelude.h" #ifdef REAL_TIMING # include "timer.h" #else struct Timer { int ms_since_start() { return 0; } }; #endif using std::vector; using std::cin; using std::cerr; using std::cout; using std::endl; #if __GNUC__ == 2 extern "C" { long int lrand48 (void); } #else # include #endif #ifndef NUM #define NUM 160000 #endif using namespace fcpp; struct Tree { int data; Tree *left; Tree *right; Tree( int x ) : data(x), left(0), right(0) {} Tree( int x, Tree* l, Tree* r ) : data(x), left(l), right(r) {} bool leaf() const { return (left==0) && (right==0); } }; // add to binary tree void insert( Tree*& root, int data ) { if( root == 0 ) root = new Tree( data ); else if( root->data < data ) insert( root->right, data ); else insert( root->left, data ); } // make a tree out of a list of numbers Tree* make_tree( const vector& v ) { Tree *t = 0; for( vector::const_iterator i = v.begin(); i != v.end(); i++ ) insert( t, *i ); return t; } struct Fringe : public CFunType > { OddList operator()( Tree* t ) const { if( t==0 ) return NIL; else if( t->leaf() ) return cons(t->data,NIL); else return cat( Fringe()(t->left), curry(Fringe(),t->right) ); } }; Fringe fringe; extern "C" void bodyx( Tree* t ) { List l = fringe(t); cout << length(l) << endl; /* l = filter( fcpp::equal(13), l ); while( !null(l) ) { cout << head(l) << endl; l = tail(l); } */ } extern "C" void body( Tree* t ) { bodyx(t); } int main() { int N = NUM; Timer timer; vector v( N ); for( int i=0; i l = fringe(t); /* cout << length(l) << endl; */ // l = filter( fcpp::equal(13), l ); l = curry2( filter, fcpp::equal(13), l ); while( !null(l) ) { cout << head(l) << endl; l = tail(l); } int end = timer.ms_since_start(); cout << "took " << end-start << " ms" << endl; return 0; }