---
# System prepended metadata

title: G Consensus order function

---

# G Consensus order function

The code sample below shows the implementation of the consensus order function.

```
1 bool o r d e r l e s s ( const Event a , const Event b ) @sa fe {
2 o r d e r c o m p a r e i t e r a t i o n c o u n t ++;
3 i f ( a . r e c e i v e d o r d e r i s b . r e c e i v e d o r d e r ) {
4 i f ( a . mother && b . mother ) {
5 return o r d e r l e s s ( a . mother , b . mother ) ;
6 }
7 i f ( a . f a t h e r && b . f a t h e r ) {
8 return o r d e r l e s s ( a . f a t h e r , b . f a t h e r ) ;
9 }
10 i f ( ! a . f a t h e r ) {
11 return f a l s e ;
12 }
13 i f ( b . f a t h e r ) {
14 return true ;
15 }
16
17 bool r a r e l e s s ( B u f f e r a , B u f f e r b ) {
18 const ab = hashgraph . hi r p c . ne t . c alcH a sh ( a ˜ b ) ;
19 const ba = hashgraph . hi r p c . ne t . c alcH a sh ( b ˜ a ) ;
20 const A = ( BitMask ( ab ) . count ) ;
21 const B = ( BitMask ( ba ) . count ) ;
22 i f (A i s B) {
23 return r a r e l e s s ( ab , ba ) ;
24 }
25 return A < B;
26 }
27
28 return r a r e l e s s ( a . f i n g e r p r i n t , b . f i n g e r p r i n t ) ;
29 }
30 return a . r e c e i v e d o r d e r < b . r e c e i v e d o r d e r ;
}


