table integrate once ...

Prev Next

Function Names

table integrate once, table integrate once ignore case

Description

This function combines the lookup strategy from table lookup once() with the data integration features of table integrate().

This function works very similarly like table integrate(), with the only difference that every row in the lookup table can be be retrieved only once and will then be internally marked as taken. Further lookups for remaining rows in the target table will skip the lookup table rows already taken. The search time ratio versus table size n is O ( log(n) ).

Function 'table integrate once'

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled

Parameter count

6 - 9 (For parameter description and return values: see table integrate() )

Examples

       table initialize( lookup,
       {  {  Names, Sports,      Scores },
          {  Abel,  tennis,      10 },          {  Bea,   squash, 14 },
          {  Chuck, racquetball, 13 },          {  Dan,   tennis, 8 },
          {  Eva,   squash,       9 },          {  Finn,  tennis, 12 },
          {  Gini,  racquetball, 12 },          {  Hugo,  squash, 11 } } );

       table initialize( target, {{ Sport, Name, Score 1, Score 2, Score 3, Score 4 },
               { racquetball, "", 5, 100, 12  },
               { squash,      "", 5, 100, 12  },
               { tennis,      "", 5, 300, 10  },
               { racquetball, "", 1, 100, 55  },
               { tennis,      "", 5, 100, 12,8  } } );

       // Picks the 1st match and integrates the results
       count[] = table integrate once ( target, Sport,  { Name,  Score 1 .. Score 4 },
                                        lookup, Sports, { Names, 4:Scores }, { overwrite, add, sub, max, average }, true, Counter );

       echo("Lookup table polled:");
       table list( lookup );

       echo("Target table after lookup (", count[], " items found):");
       table list ( target );

Output

Lookup table polled:
    0 : Names | Sports      | Scores | Counter
    1 : Abel  | tennis      | 10     | 1      
    2 : Bea   | squash      | 14     | 1      
    3 : Chuck | racquetball | 13     | 1      
    4 : Dan   | tennis      | 8      | 1      
    5 : Eva   | squash      | 9      |        
    6 : Finn  | tennis      | 12     |        
    7 : Gini  | racquetball | 12     | 1      
    8 : Hugo  | squash      | 11     |        

Target table after lookup (5 items found):
    0 : Sport       | Name  | Score 1 | Score 2 | Score 3 | Score 4
    1 : racquetball | Chuck | 18      | 87      | 13      | 6.5    
    2 : squash      | Bea   | 19      | 86      | 14      | 7      
    3 : tennis      | Abel  | 15      | 290     | 10      | 5      
    4 : racquetball | Gini  | 13      | 88      | 55      | 6      
    5 : tennis      | Dan   | 13      | 92      | 12      | 8      

Try it yourself: Open LIB_Function_table_integrate_once.b4p in B4P_Examples.zip. Decompress before use.

See also

table integrate
table lookup once