#ifndef TASK01_EVENT_GROUPS_MODEL_H #define TASK01_EVENT_GROUPS_MODEL_H #include #include typedef struct EventGroupEvidence { uint32_t sequence; uint32_t event; uint32_t tick; uint32_t actor; uint32_t value; uint32_t committed; } EventGroupEvidence; static inline uint32_t fc09_digest( const EventGroupEvidence * events, size_t count ) { uint32_t hash = 2166136261U; size_t index; for( index = 0U; index < count; ++index ) { hash = ( hash ^ events[ index ].event ) * 16777619U; hash = ( hash ^ events[ index ].actor ) * 16777619U; hash = ( hash ^ events[ index ].value ) * 16777619U; hash = ( hash ^ events[ index ].committed ) * 16777619U; } return hash; } static inline int fc09_mask_contains( uint32_t value, uint32_t mask ) { return ( value & mask ) == mask; } static inline int fc09_order_is_valid( const EventGroupEvidence * events, size_t count ) { size_t index; if( events == NULL || count != 11U ) { return 0; } for( index = 0U; index < count; ++index ) { if( events[ index ].sequence != index + 1U || events[ index ].event != index + 1U || events[ index ].committed != ( 0xFC090000U | ( index + 1U ) ) ) { return 0; } } return 1; } #endif