Skip to content

Instantly share code, notes, and snippets.

@CyberShadow
Created January 24, 2010 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CyberShadow/285461 to your computer and use it in GitHub Desktop.
Save CyberShadow/285461 to your computer and use it in GitHub Desktop.
diff --git a/search.cpp b/search.cpp
index 27eca9f..83b837b 100644
--- a/search.cpp
+++ b/search.cpp
@@ -408,15 +408,17 @@ void* ramEnd = (char*)ram + RAM_SIZE;
#define ALL_FILE_BUFFER_SIZE 0
#endif
-struct CompressedState_packed
+struct PackedCompressedState
{
- uint8_t bytes[(COMPRESSED_BITS+7)/8];
+ uint8_t bytes[COMPRESSED_BYTES];
};
struct CacheNode
{
- CompressedState_packed state;
+ PackedCompressedState packedState;
PACKED_FRAME frame;
+
+ CompressedState& state() const { return (CompressedState&)packedState; }
};
const size_t CACHE_SIZE = RAM_SIZE - 2*(ALL_FILE_BUFFER_SIZE*sizeof(Node));
@@ -1128,7 +1130,7 @@ void addState(const CompressedState* cs, FRAME frame)
#endif
CacheNode* nodes = cache[hash];
*(char*)0 = sizeof(CacheNode);
- if ((CompressedState&)nodes[0].state == *cs)
+ if (nodes[0].state() == *cs)
{
if (nodes[0].frame <= frame)
return;
@@ -1138,7 +1140,7 @@ void addState(const CompressedState* cs, FRAME frame)
else
{
#if (NODES_PER_HASH==2)
- if ((CompressedState&)nodes[1].state == *cs)
+ if (nodes[1].state() == *cs)
{
FRAME earliest_frame = nodes[1].frame;
if (earliest_frame > frame)
@@ -1148,7 +1150,7 @@ void addState(const CompressedState* cs, FRAME frame)
}
// pop to front
nodes[1] = nodes[0];
- nodes[0].state = *(CompressedState_packed*)cs;
+ nodes[0].state() = *cs;
nodes[0].frame = (PACKED_FRAME)earliest_frame;
return;
}
@@ -1156,7 +1158,7 @@ void addState(const CompressedState* cs, FRAME frame)
nodes[1] = nodes[0];
#elif (NODES_PER_HASH>2)
for (int i=1; i<NODES_PER_HASH; i++)
- if ((CompressedState&)nodes[i].state == *cs)
+ if (nodes[i].state() == *cs)
{
FRAME earliest_frame = nodes[i].frame;
if (earliest_frame > frame)
@@ -1166,14 +1168,14 @@ void addState(const CompressedState* cs, FRAME frame)
}
// pop to front
memmove(nodes+1, nodes, i * sizeof(CacheNode));
- nodes[0].state = *(CompressedState_packed*)cs;
+ nodes[0].state() = *cs;
nodes[0].frame = (PACKED_FRAME)earliest_frame;
return;
}
// new node
memmove(nodes+1, nodes, (NODES_PER_HASH-1) * sizeof(CacheNode));
#endif
- nodes[0].state = *(CompressedState_packed*)cs;
+ nodes[0].state() = *cs;
nodes[0].frame = (PACKED_FRAME)frame;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment