get rid of legacy "incorrect" stuff around hashing

This commit is contained in:
katianderic 2020-03-13 21:01:36 -07:00
parent 1a082f7f15
commit 901b70a5f2
5 changed files with 16 additions and 26 deletions

View file

@ -391,8 +391,7 @@ mem_stream_getSize( const XWStreamCtxt* p_sctx )
} /* mem_stream_getSize */
static XP_U32
mem_stream_getHash( const XWStreamCtxt* p_sctx, XWStreamPos pos,
XP_Bool correct )
mem_stream_getHash( const XWStreamCtxt* p_sctx, XWStreamPos pos )
{
XP_U32 hash = 0;
const MemStreamCtxt* stream = (const MemStreamCtxt*)p_sctx;
@ -409,11 +408,7 @@ mem_stream_getHash( const XWStreamCtxt* p_sctx, XWStreamPos pos,
hash = augmentHash( 0, ptr, len );
if ( 0 != bits ) {
XP_U8 byt = ptr[len];
if ( correct ) {
byt &= ~(0xFF << bits);
} else {
byt &= 1 << bits;
}
byt &= ~(0xFF << bits);
hash = augmentHash( hash, &byt, 1 );
LOG_HEX( &byt, 1, __func__ );
}

View file

@ -320,15 +320,14 @@ model_getHash( const ModelCtxt* model )
#endif
StackCtxt* stack = model->vol.stack;
XP_ASSERT( !!stack );
return stack_getHash( stack, XP_TRUE );
return stack_getHash( stack );
}
XP_Bool
model_hashMatches( const ModelCtxt* model, const XP_U32 hash )
{
StackCtxt* stack = model->vol.stack;
XP_Bool matches = hash == stack_getHash( stack, XP_TRUE )
|| hash == stack_getHash( stack, XP_FALSE );
XP_Bool matches = hash == stack_getHash( stack );
return matches;
}
@ -342,8 +341,7 @@ model_popToHash( ModelCtxt* model, const XP_U32 hash, PoolContext* pool )
XP_S16 foundAt = -1;
for ( XP_U16 ii = 0; ii < nEntries; ++ii ) {
if ( hash == stack_getHash( stack, XP_TRUE )
|| hash == stack_getHash( stack, XP_FALSE ) ) {
if ( hash == stack_getHash( stack ) ) {
foundAt = ii;
break;
}
@ -369,8 +367,7 @@ model_popToHash( ModelCtxt* model, const XP_U32 hash, PoolContext* pool )
model_undoLatestMoves( model, pool, foundAt, NULL, NULL );
XP_ASSERT( success );
/* Assert not needed for long */
XP_ASSERT( hash == stack_getHash( model->vol.stack, XP_TRUE )
|| hash == stack_getHash( model->vol.stack, XP_FALSE ) );
XP_ASSERT( hash == stack_getHash( model->vol.stack ) );
} else {
XP_ASSERT( nEntries == stack_getNEntries(stack) );
}

View file

@ -74,11 +74,11 @@ stack_init( StackCtxt* stack, XP_U16 nPlayers, XP_Bool inDuplicateMode )
#ifdef STREAM_VERS_HASHSTREAM
XP_U32
stack_getHash( const StackCtxt* stack, XP_Bool correct )
stack_getHash( const StackCtxt* stack )
{
XP_U32 hash = 0;
if ( !!stack->data ) {
hash = stream_getHash( stack->data, stack->top, correct );
hash = stream_getHash( stack->data, stack->top );
}
return hash;
} /* stack_getHash */
@ -271,8 +271,7 @@ static void
pushEntry( StackCtxt* stack, const StackEntry* entry )
{
#ifdef DEBUG_HASHING
XP_Bool correct = XP_TRUE;
XP_U32 origHash = stack_getHash( stack, correct );
XP_U32 origHash = stack_getHash( stack );
StackEntry prevTop;
if ( 1 < stack->nPlayers &&
@ -284,12 +283,12 @@ pushEntry( StackCtxt* stack, const StackEntry* entry )
pushEntryImpl( stack, entry );
#ifdef DEBUG_HASHING
XP_U32 newHash = stack_getHash( stack, XP_TRUE );
XP_U32 newHash = stack_getHash( stack );
StackEntry lastEntry;
if ( stack_popEntry( stack, &lastEntry ) ) {
XP_ASSERT( origHash == stack_getHash( stack, correct ) );
XP_ASSERT( origHash == stack_getHash( stack ) );
pushEntryImpl( stack, &lastEntry );
XP_ASSERT( newHash == stack_getHash( stack, correct ) );
XP_ASSERT( newHash == stack_getHash( stack ) );
XP_LOGFF( "all ok; pushed type %s for player %d into pos #%d, hash now %X (was %X)",
StackMoveType_2str(entry->moveType), entry->playerNum,
stack->nEntries, newHash, origHash );

View file

@ -86,7 +86,7 @@ StackCtxt* stack_make( MPFORMAL VTableMgr* vtmgr, XP_U16 nPlayers, XP_Bool inDup
void stack_destroy( StackCtxt* stack );
void stack_init( StackCtxt* stack, XP_U16 nPlayers, XP_Bool inDuplicateMode );
XP_U32 stack_getHash( const StackCtxt* stack, XP_Bool correct );
XP_U32 stack_getHash( const StackCtxt* stack );
void stack_setBitsPerTile( StackCtxt* stack, XP_U16 bitsPerTile );
void stack_loadFromStream( StackCtxt* stack, XWStreamCtxt* stream );

View file

@ -88,8 +88,7 @@ typedef struct StreamCtxVTable {
void (*m_stream_close)( XWStreamCtxt* dctx );
XP_U16 (*m_stream_getSize)( const XWStreamCtxt* dctx );
XP_U32 (*m_stream_getHash)( const XWStreamCtxt* dctx, XWStreamPos pos,
XP_Bool correct );
XP_U32 (*m_stream_getHash)( const XWStreamCtxt* dctx, XWStreamPos pos );
const XP_U8* (*m_stream_getPtr)( const XWStreamCtxt* dctx );
@ -171,8 +170,8 @@ struct XWStreamCtxt {
#define stream_getSize(sc) \
(sc)->vtable->m_stream_getSize((sc))
#define stream_getHash(sc, p, c) \
(sc)->vtable->m_stream_getHash((sc), (p), (c))
#define stream_getHash(sc, p) \
(sc)->vtable->m_stream_getHash((sc), (p))
#define stream_getPtr(sc) \
(sc)->vtable->m_stream_getPtr((sc))