新增 StackAlloc 不过暂未启用
This commit is contained in:
parent
51be7b9490
commit
a22c06018a
|
@ -35,6 +35,7 @@ HEADERS += \
|
|||
src/HashNode.h \
|
||||
src/MemoryPool.h \
|
||||
src/MemoryPool.tcc \
|
||||
src/StackAlloc.h \
|
||||
src/boarditem.h \
|
||||
src/client.h \
|
||||
src/config.h \
|
||||
|
|
|
@ -518,6 +518,7 @@
|
|||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;$(QTDIR)\include;.\release;\include;$(QTDIR)\mkspecs\win32-msvc;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtMultimedia;$(QTDIR)\include\QtNetwork</IncludePath>
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;$(QTDIR)\include;.\release;\include;$(QTDIR)\mkspecs\win32-msvc;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtMultimedia;$(QTDIR)\include\QtNetwork</IncludePath>
|
||||
</QtMoc>
|
||||
<ClInclude Include="src\StackAlloc.h" />
|
||||
<ClInclude Include="src\zobrist.h" />
|
||||
<ClInclude Include="ui_ninechesswindow.h" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -128,6 +128,9 @@
|
|||
<ClInclude Include="src\MemoryPool.h">
|
||||
<Filter>Model</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\StackAlloc.h">
|
||||
<Filter>Model</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="debug\moc_predefs.h.cbt">
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
/*-
|
||||
* Copyright (c) 2013 Cosku Acay, http://www.coskuacay.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
/*-
|
||||
* A template class that implements a simple stack structure.
|
||||
* This demostrates how to use alloctor_traits (specifically with MemoryPool)
|
||||
*/
|
||||
|
||||
#ifndef STACK_ALLOC_H
|
||||
#define STACK_ALLOC_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
template <typename T>
|
||||
struct StackNode_
|
||||
{
|
||||
T data;
|
||||
StackNode_* prev;
|
||||
};
|
||||
|
||||
/** T is the object to store in the stack, Alloc is the allocator to use */
|
||||
template <class T, class Alloc = std::allocator<T> >
|
||||
class StackAlloc
|
||||
{
|
||||
public:
|
||||
typedef StackNode_<T> Node;
|
||||
typedef typename Alloc::template rebind<Node>::other allocator;
|
||||
|
||||
/** Default constructor */
|
||||
StackAlloc() {head_ = 0; }
|
||||
/** Default destructor */
|
||||
~StackAlloc() { clear(); }
|
||||
|
||||
/** Returns true if the stack is empty */
|
||||
bool empty() {return (head_ == 0);}
|
||||
|
||||
/** Deallocate all elements and empty the stack */
|
||||
void clear() {
|
||||
Node* curr = head_;
|
||||
while (curr != 0)
|
||||
{
|
||||
Node* tmp = curr->prev;
|
||||
allocator_.destroy(curr);
|
||||
allocator_.deallocate(curr, 1);
|
||||
curr = tmp;
|
||||
}
|
||||
head_ = 0;
|
||||
}
|
||||
|
||||
/** Put an element on the top of the stack */
|
||||
void push(T element) {
|
||||
Node* newNode = allocator_.allocate(1);
|
||||
allocator_.construct(newNode, Node());
|
||||
newNode->data = element;
|
||||
newNode->prev = head_;
|
||||
head_ = newNode;
|
||||
}
|
||||
|
||||
/** Remove and return the topmost element on the stack */
|
||||
T pop() {
|
||||
T result = head_->data;
|
||||
Node* tmp = head_->prev;
|
||||
allocator_.destroy(head_);
|
||||
allocator_.deallocate(head_, 1);
|
||||
head_ = tmp;
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Return the topmost element */
|
||||
T top() { return (head_->data); }
|
||||
|
||||
private:
|
||||
allocator allocator_;
|
||||
Node* head_;
|
||||
};
|
||||
|
||||
#endif // STACK_ALLOC_H
|
|
@ -22,8 +22,14 @@
|
|||
#ifndef NINECHESSAI_AB
|
||||
#define NINECHESSAI_AB
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <list>
|
||||
//#ifdef MEMORY_POOL
|
||||
//#include "StackAlloc.h"
|
||||
//#else
|
||||
#include <stack>
|
||||
//#endif
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <Qdebug>
|
||||
|
@ -219,7 +225,11 @@ private:
|
|||
#endif
|
||||
|
||||
// 局面数据栈
|
||||
//#ifdef MEMORY_POOL
|
||||
// StackAlloc<NineChess::ChessContext, MemoryPool<NineChess::ChessContext> > contextStack;
|
||||
//#else
|
||||
stack<NineChess::ChessContext> contextStack;
|
||||
//#endif
|
||||
|
||||
// 标识,用于跳出剪枝算法,立即返回
|
||||
bool requiredQuit;
|
||||
|
|
Loading…
Reference in New Issue