/* * Insert a single element into the set in no particular order. * The element is a data item. A container node will be allocated * to link in the element. */ void Escher_SetInsertElement( Escher_ObjectSet_s * set, void * const substance ) { Escher_SetElement_s * slot; if ( 0 == node1_FreeList.head ) { Escher_SetElement_s * new_mem = ( Escher_SetElement_s *) Escher_malloc( 10 * sizeof( Escher_SetElement_s ) ); if ( 0 == new_mem ) { UserNodeListEmptyCallout(); /* Bad news! No more heap space. */ } else { i_t i; for ( i = 0; i < 10 - 1; i++ ) { new_mem[ i ].next = (Escher_SetElement_s *) &(new_mem[ i + 1 ]); } new_mem[ 10 - 1 ].next = 0; node1_FreeList.head = new_mem; } } slot = node1_FreeList.head; /* Extract node from free list head. */ node1_FreeList.head = node1_FreeList.head->next; slot->object = substance; slot->next = set->head; /* Insert substance at list front. */ set->head = slot; }
/* * Insert a single element into the set in no particular order. * The element is a data item. A container node will be allocated * to link in the element. */ void Escher_SetInsertElement( Escher_ObjectSet_s * set, void * const substance ) { Escher_SetElement_s * slot; if ( 0 == node1_FreeList.head ) { UserNodeListEmptyCallout(); /* Bad news! No more nodes. */ } else { slot = node1_FreeList.head; /* Extract node from free list head. */ node1_FreeList.head = node1_FreeList.head->next; slot->object = substance; slot->next = set->head; /* Insert substance at list front. */ set->head = slot; } }