gpointerqueue.h

来自「一个由Mike Gashler完成的机器学习方面的includes neural」· C头文件 代码 · 共 140 行

H
140
字号
/*	Copyright (C) 2006, Mike Gashler	This library is free software; you can redistribute it and/or	modify it under the terms of the GNU Lesser General Public	License as published by the Free Software Foundation; either	version 2.1 of the License, or (at your option) any later version.	see http://www.gnu.org/copyleft/lesser.html*/#ifndef __GPOINTERQUEUE_H__#define __GPOINTERQUEUE_H__#include "GMacros.h"class GPointerQueueChunk{public:	GPointerQueueChunk* m_pNext;	void** m_pData;	GPointerQueueChunk(int nChunkSize);	~GPointerQueueChunk();};// Represents a FIFO queue of pointersclass GPointerQueue{protected:	int m_nChunkSize;	int m_nInPos;	int m_nOutPos;	int m_nDataSize;	GPointerQueueChunk* m_pFirstChunk;	GPointerQueueChunk* m_pLastChunk;	GPointerQueueChunk* m_pExtra;public:	GPointerQueue(int nChunkSize = 1024);	virtual ~GPointerQueue();	void Flush();	// Add a pointer to the queue	inline void Push(void* pointer)	{		if(m_nInPos >= m_nChunkSize)			GetNewChunk();		m_pLastChunk->m_pData[m_nInPos++] = pointer;		m_nDataSize++;	}	// Read the next pointer from the queue	inline void* Pop()	{		GAssert(m_nDataSize > 0, "The queue is empty");		void* pPointer = m_pFirstChunk->m_pData[m_nOutPos++];		m_nDataSize--;		if(m_nOutPos >= m_nChunkSize)			ThrowOutChunk();		return pPointer;	}	// Peek at the next pointer, but don't actually pop it	inline void* Peek()	{		GAssert(m_nDataSize > 0, "The queue is empty");		return m_pFirstChunk->m_pData[m_nOutPos];	}	// Returns how many pointers are in the queue	inline int GetSize() { return m_nDataSize; }protected:	void GetNewChunk();	void ThrowOutChunk();	void Link(GPointerQueueChunk* pChunk);	GPointerQueueChunk* UnlinkFirst();};class GIntQueue{protected:	int m_nChunkSize;	int m_nInPos;	int m_nOutPos;	int m_nDataSize;	GPointerQueueChunk* m_pFirstChunk;	GPointerQueueChunk* m_pLastChunk;	GPointerQueueChunk* m_pExtra;public:	GIntQueue(int nChunkSize = 1024);	virtual ~GIntQueue();	void Flush();	// Add an int to the queue	inline void Push(int i)	{		if(m_nInPos >= m_nChunkSize)			GetNewChunk();		((int*)m_pLastChunk->m_pData)[m_nInPos++] = i;		m_nDataSize++;	}	// Read the next int from the queue	inline int Pop()	{		GAssert(m_nDataSize > 0, "The queue is empty");		int i = ((int*)m_pFirstChunk->m_pData)[m_nOutPos++];		m_nDataSize--;		if(m_nOutPos >= m_nChunkSize)			ThrowOutChunk();		return i;	}	// Peek at the next int, but don't actually pop it	inline int Peek()	{		GAssert(m_nDataSize > 0, "The queue is empty");		return ((int*)m_pFirstChunk->m_pData)[m_nOutPos];	}	// Returns how many ints are in the queue	inline int GetSize() { return m_nDataSize; }protected:	void GetNewChunk();	void ThrowOutChunk();	void Link(GPointerQueueChunk* pChunk);	GPointerQueueChunk* UnlinkFirst();};#endif // __GPOINTERQUEUE_H__

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?