#include "insrcdata.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
static unsigned const CLIENT_TABLE_COUNT = 3;
static const client_t CLIENT_TABLE[CLIENT_TABLE_COUNT] = {
{"John", },
{"Alix", },
{"David", },
};
const client_t* client_next(client_iter_t* idx) { return idx->ptr<idx->end ? &CLIENT_TABLE[*idx->ptr++] : NULL; }
const client_t* client_from_clients(clients_t label) {
return &CLIENT_TABLE[label];
}
clients_t client_clients(const client_t *s) {
return (clients_t)(s-CLIENT_TABLE);
}
static unsigned const PRODUCT_TABLE_COUNT = 4;
static const product_t PRODUCT_TABLE[PRODUCT_TABLE_COUNT] = {
{"Apple", },
{"Banana", },
{"Peach", },
{"Cherry", },
};
const product_t* product_next(product_iter_t* idx) { return idx->ptr<idx->end ? &PRODUCT_TABLE[*idx->ptr++] : NULL; }
const product_t* product_from_products(products_t label) {
return &PRODUCT_TABLE[label];
}
products_t product_products(const product_t *s) {
return (products_t)(s-PRODUCT_TABLE);
}
static unsigned const TRANSACTION_TABLE_COUNT = 7;
static const transaction_t TRANSACTION_TABLE[TRANSACTION_TABLE_COUNT] = {
{0, 0, },
{0, 1, },
{1, 0, },
{1, 2, },
{2, 0, },
{2, 1, },
{2, 2, },
};
const transaction_t* transaction_next(transaction_iter_t* idx) { return idx->ptr<idx->end ? &TRANSACTION_TABLE[*idx->ptr++] : NULL; }
static unsigned const TRANSACTION_CLIENT_INDEX_COUNT = 7;
static uint8_t TRANSACTION_CLIENT_INDEX [TRANSACTION_CLIENT_INDEX_COUNT] = {
0, 1, 2, 3, 4, 5, 6,
};
static unsigned const TRANSACTION_PRODUCT_INDEX_COUNT = 7;
static uint8_t TRANSACTION_PRODUCT_INDEX [TRANSACTION_PRODUCT_INDEX_COUNT] = {
0, 2, 4, 1, 5, 3, 6,
};
transaction_iter_t client_transactions(const client_t* s) {
long cons = s - CLIENT_TABLE;
uint8_t* lo = TRANSACTION_CLIENT_INDEX;
uint8_t* hi = TRANSACTION_CLIENT_INDEX + TRANSACTION_CLIENT_INDEX_COUNT;
while( lo < hi ){
uint8_t* mid = lo + ( hi-lo)/2;
if ( cons > TRANSACTION_TABLE[*mid].client_ ) {
lo = mid + 1;
} else {
hi = mid;
}
}
uint8_t* begin = lo;
hi = TRANSACTION_CLIENT_INDEX + TRANSACTION_CLIENT_INDEX_COUNT;
while( lo < hi ){
uint8_t* mid = lo + ( hi-lo)/2;
if( cons < TRANSACTION_TABLE[*mid].client_ ) {
hi = mid;
} else {
lo = mid + 1;
}
}
transaction_iter_t res = { begin, lo };
return res;
}
transaction_iter_t product_transactions(const product_t* s) {
long cons = s - PRODUCT_TABLE;
uint8_t* lo = TRANSACTION_PRODUCT_INDEX;
uint8_t* hi = TRANSACTION_PRODUCT_INDEX + TRANSACTION_PRODUCT_INDEX_COUNT;
while( lo < hi ){
uint8_t* mid = lo + ( hi-lo)/2;
if ( cons > TRANSACTION_TABLE[*mid].product_ ) {
lo = mid + 1;
} else {
hi = mid;
}
}
uint8_t* begin = lo;
hi = TRANSACTION_PRODUCT_INDEX + TRANSACTION_PRODUCT_INDEX_COUNT;
while( lo < hi ){
uint8_t* mid = lo + ( hi-lo)/2;
if( cons < TRANSACTION_TABLE[*mid].product_ ) {
hi = mid;
} else {
lo = mid + 1;
}
}
transaction_iter_t res = { begin, lo };
return res;
}
const client_t* transaction_client(const transaction_t* s) { return &CLIENT_TABLE[s->client_];}
const product_t* transaction_product(const transaction_t* s) { return &PRODUCT_TABLE[s->product_];}