This commit is contained in:
2024-08-16 13:56:19 -04:00
parent 08cded0b44
commit 75df00b3e3
5 changed files with 149 additions and 494 deletions

View File

@@ -1,330 +0,0 @@
# Microsoft Developer Studio Generated NMAKE File, Format Version 4.20
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
!IF "$(CFG)" == ""
CFG=bsptree - Win32 Debug
!MESSAGE No configuration specified. Defaulting to bsptree - Win32 Debug.
!ENDIF
!IF "$(CFG)" != "bsptree - Win32 Release" && "$(CFG)" !=\
"bsptree - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE on this makefile
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Bsptree.mak" CFG="bsptree - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "bsptree - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "bsptree - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
################################################################################
# Begin Project
# PROP Target_Last_Scanned "bsptree - Win32 Debug"
CPP=cl.exe
!IF "$(CFG)" == "bsptree - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
OUTDIR=.\Release
INTDIR=.\Release
ALL : "$(OUTDIR)\Bsptree.lib"
CLEAN :
-@erase "$(INTDIR)\Bsptmpl.obj"
-@erase "$(INTDIR)\Rgbtree.obj"
-@erase "$(INTDIR)\Stdtmpl.obj"
-@erase "$(OUTDIR)\Bsptree.lib"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS"\
/Fp"$(INTDIR)/Bsptree.pch" /YX /Fo"$(INTDIR)/" /c
CPP_OBJS=.\Release/
CPP_SBRS=.\.
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
BSC32_FLAGS=/nologo /o"$(OUTDIR)/Bsptree.bsc"
BSC32_SBRS= \
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
LIB32_FLAGS=/nologo /out:"$(OUTDIR)/Bsptree.lib"
LIB32_OBJS= \
"$(INTDIR)\Bsptmpl.obj" \
"$(INTDIR)\Rgbtree.obj" \
"$(INTDIR)\Stdtmpl.obj"
"$(OUTDIR)\Bsptree.lib" : "$(OUTDIR)" $(DEF_FILE) $(LIB32_OBJS)
$(LIB32) @<<
$(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS)
<<
!ELSEIF "$(CFG)" == "bsptree - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "msvcobj"
# PROP Intermediate_Dir "msvcobj"
# PROP Target_Dir ""
OUTDIR=.\msvcobj
INTDIR=.\msvcobj
ALL : "..\exe\msbsp.lib"
CLEAN :
-@erase "$(INTDIR)\Bsptmpl.obj"
-@erase "$(INTDIR)\Rgbtree.obj"
-@erase "$(INTDIR)\Stdtmpl.obj"
-@erase "..\exe\msbsp.lib"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /MTd /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "__FLAT__" /D "STRICT" /Fp"c:\work\exe\msvc42.pch" /YX /c
CPP_PROJ=/nologo /MTd /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D\
"__FLAT__" /D "STRICT" /Fp"c:\work\exe\msvc42.pch" /YX /Fo"$(INTDIR)/" /c
CPP_OBJS=.\msvcobj/
CPP_SBRS=.\.
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
BSC32_FLAGS=/nologo /o"$(OUTDIR)/Bsptree.bsc"
BSC32_SBRS= \
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"..\exe\msbsp.lib"
LIB32_FLAGS=/nologo /out:"..\exe\msbsp.lib"
LIB32_OBJS= \
"$(INTDIR)\Bsptmpl.obj" \
"$(INTDIR)\Rgbtree.obj" \
"$(INTDIR)\Stdtmpl.obj"
"..\exe\msbsp.lib" : "$(OUTDIR)" $(DEF_FILE) $(LIB32_OBJS)
$(LIB32) @<<
$(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS)
<<
!ENDIF
.c{$(CPP_OBJS)}.obj:
$(CPP) $(CPP_PROJ) $<
.cpp{$(CPP_OBJS)}.obj:
$(CPP) $(CPP_PROJ) $<
.cxx{$(CPP_OBJS)}.obj:
$(CPP) $(CPP_PROJ) $<
.c{$(CPP_SBRS)}.sbr:
$(CPP) $(CPP_PROJ) $<
.cpp{$(CPP_SBRS)}.sbr:
$(CPP) $(CPP_PROJ) $<
.cxx{$(CPP_SBRS)}.sbr:
$(CPP) $(CPP_PROJ) $<
################################################################################
# Begin Target
# Name "bsptree - Win32 Release"
# Name "bsptree - Win32 Debug"
!IF "$(CFG)" == "bsptree - Win32 Release"
!ELSEIF "$(CFG)" == "bsptree - Win32 Debug"
!ENDIF
################################################################################
# Begin Source File
SOURCE=.\Stdtmpl.cpp
!IF "$(CFG)" == "bsptree - Win32 Release"
DEP_CPP_STDTM=\
{$(INCLUDE)}"\.\Btree.hpp"\
{$(INCLUDE)}"\.\Btree.tpp"\
{$(INCLUDE)}"\.\Treenode.hpp"\
{$(INCLUDE)}"\.\Treenode.tpp"\
{$(INCLUDE)}"\Common\array.hpp"\
{$(INCLUDE)}"\Common\Assert.hpp"\
{$(INCLUDE)}"\Common\Block.hpp"\
{$(INCLUDE)}"\Common\Block.tpp"\
{$(INCLUDE)}"\Common\except.hpp"\
{$(INCLUDE)}"\Common\Fixup.hpp"\
{$(INCLUDE)}"\Common\Pointer.hpp"\
{$(INCLUDE)}"\Common\Pvector.hpp"\
{$(INCLUDE)}"\Common\Pvector.tpp"\
{$(INCLUDE)}"\Common\Stdlib.hpp"\
{$(INCLUDE)}"\Common\String.hpp"\
{$(INCLUDE)}"\Common\Types.hpp"\
{$(INCLUDE)}"\Common\Windows.hpp"\
"$(INTDIR)\Stdtmpl.obj" : $(SOURCE) $(DEP_CPP_STDTM) "$(INTDIR)"
!ELSEIF "$(CFG)" == "bsptree - Win32 Debug"
DEP_CPP_STDTM=\
{$(INCLUDE)}"\.\Btree.hpp"\
{$(INCLUDE)}"\.\Btree.tpp"\
{$(INCLUDE)}"\.\Treenode.hpp"\
{$(INCLUDE)}"\.\Treenode.tpp"\
{$(INCLUDE)}"\Common\array.hpp"\
{$(INCLUDE)}"\Common\Assert.hpp"\
{$(INCLUDE)}"\Common\Block.hpp"\
{$(INCLUDE)}"\Common\Block.tpp"\
{$(INCLUDE)}"\Common\except.hpp"\
{$(INCLUDE)}"\Common\Fixup.hpp"\
{$(INCLUDE)}"\Common\Pointer.hpp"\
{$(INCLUDE)}"\Common\Pvector.hpp"\
{$(INCLUDE)}"\Common\Pvector.tpp"\
{$(INCLUDE)}"\Common\String.hpp"\
{$(INCLUDE)}"\Common\Types.hpp"\
{$(INCLUDE)}"\Common\Windows.hpp"\
"$(INTDIR)\Stdtmpl.obj" : $(SOURCE) $(DEP_CPP_STDTM) "$(INTDIR)"
!ENDIF
# End Source File
################################################################################
# Begin Source File
SOURCE=.\Rgbtree.cpp
!IF "$(CFG)" == "bsptree - Win32 Release"
DEP_CPP_RGBTR=\
{$(INCLUDE)}"\.\Btree.hpp"\
{$(INCLUDE)}"\.\Btree.tpp"\
{$(INCLUDE)}"\.\Colorkey.hpp"\
{$(INCLUDE)}"\.\Rgbndx.hpp"\
{$(INCLUDE)}"\.\Rgbstack.hpp"\
{$(INCLUDE)}"\.\Rgbtree.hpp"\
{$(INCLUDE)}"\.\Treendex.hpp"\
{$(INCLUDE)}"\.\Treenode.hpp"\
{$(INCLUDE)}"\.\Treenode.tpp"\
{$(INCLUDE)}"\Common\array.hpp"\
{$(INCLUDE)}"\Common\Assert.hpp"\
{$(INCLUDE)}"\Common\Block.hpp"\
{$(INCLUDE)}"\Common\Block.tpp"\
{$(INCLUDE)}"\Common\except.hpp"\
{$(INCLUDE)}"\Common\Fixup.hpp"\
{$(INCLUDE)}"\Common\Palentry.hpp"\
{$(INCLUDE)}"\Common\Pointer.hpp"\
{$(INCLUDE)}"\Common\Pvector.hpp"\
{$(INCLUDE)}"\Common\Pvector.tpp"\
{$(INCLUDE)}"\Common\Rgbcolor.hpp"\
{$(INCLUDE)}"\Common\Types.hpp"\
{$(INCLUDE)}"\Common\Windows.hpp"\
"$(INTDIR)\Rgbtree.obj" : $(SOURCE) $(DEP_CPP_RGBTR) "$(INTDIR)"
!ELSEIF "$(CFG)" == "bsptree - Win32 Debug"
DEP_CPP_RGBTR=\
{$(INCLUDE)}"\.\Btree.hpp"\
{$(INCLUDE)}"\.\Btree.tpp"\
{$(INCLUDE)}"\.\Colorkey.hpp"\
{$(INCLUDE)}"\.\Rgbndx.hpp"\
{$(INCLUDE)}"\.\Rgbstack.hpp"\
{$(INCLUDE)}"\.\Rgbtree.hpp"\
{$(INCLUDE)}"\.\Treendex.hpp"\
{$(INCLUDE)}"\.\Treenode.hpp"\
{$(INCLUDE)}"\.\Treenode.tpp"\
{$(INCLUDE)}"\Common\array.hpp"\
{$(INCLUDE)}"\Common\Assert.hpp"\
{$(INCLUDE)}"\Common\Block.hpp"\
{$(INCLUDE)}"\Common\Block.tpp"\
{$(INCLUDE)}"\Common\except.hpp"\
{$(INCLUDE)}"\Common\Fixup.hpp"\
{$(INCLUDE)}"\Common\Palentry.hpp"\
{$(INCLUDE)}"\Common\Pointer.hpp"\
{$(INCLUDE)}"\Common\Pvector.hpp"\
{$(INCLUDE)}"\Common\Pvector.tpp"\
{$(INCLUDE)}"\Common\Rgbcolor.hpp"\
{$(INCLUDE)}"\Common\Types.hpp"\
{$(INCLUDE)}"\Common\Windows.hpp"\
"$(INTDIR)\Rgbtree.obj" : $(SOURCE) $(DEP_CPP_RGBTR) "$(INTDIR)"
!ENDIF
# End Source File
################################################################################
# Begin Source File
SOURCE=.\Bsptmpl.cpp
DEP_CPP_BSPTM=\
{$(INCLUDE)}"\.\Btree.hpp"\
{$(INCLUDE)}"\.\Btree.tpp"\
{$(INCLUDE)}"\.\Colorkey.hpp"\
{$(INCLUDE)}"\.\Rgbndx.hpp"\
{$(INCLUDE)}"\.\Treendex.hpp"\
{$(INCLUDE)}"\.\Treenode.hpp"\
{$(INCLUDE)}"\.\Treenode.tpp"\
{$(INCLUDE)}"\Common\array.hpp"\
{$(INCLUDE)}"\Common\Assert.hpp"\
{$(INCLUDE)}"\Common\Block.hpp"\
{$(INCLUDE)}"\Common\Block.tpp"\
{$(INCLUDE)}"\Common\except.hpp"\
{$(INCLUDE)}"\Common\Fixup.hpp"\
{$(INCLUDE)}"\Common\Pointer.hpp"\
{$(INCLUDE)}"\Common\Pvector.hpp"\
{$(INCLUDE)}"\Common\Pvector.tpp"\
{$(INCLUDE)}"\Common\Rgbcolor.hpp"\
{$(INCLUDE)}"\Common\Types.hpp"\
{$(INCLUDE)}"\Common\Windows.hpp"\
"$(INTDIR)\Bsptmpl.obj" : $(SOURCE) $(DEP_CPP_BSPTM) "$(INTDIR)"
# End Source File
# End Target
# End Project
################################################################################

View File

@@ -1,163 +0,0 @@
#ifndef _BSPTREE_BTREE_HPP_
#define _BSPTREE_BTREE_HPP_
#ifndef _COMMON_ASSERT_HPP_
#include <common/assert.hpp>
#endif
#ifndef _COMMON_WINDOWS_HPP_
#include <common/windows.hpp>
#endif
#ifndef _COMMON_PUREVECTOR_HPP_
#include <common/pvector.hpp>
#endif
#ifndef _COMMON_BLOCK_HPP_
#include <common/block.hpp>
#endif
#ifndef _COMMON_SMARTPOINTER_HPP_
#include <common/pointer.hpp>
#endif
#ifndef _BSPTREE_TREENODE_HPP_
#include <bsptree/treenode.hpp>
#endif
template <class T>
class BTree
{
public:
BTree(void);
virtual ~BTree();
DWORD leaves(void)const;
WORD insert(const T &someItem,DWORD dupsOk=FALSE);
WORD insert(PureVector<T> &vectorItems);
void remove(const T &someItem);
BOOL searchItem(T &someItem);
BOOL searchItem(T &someItem,SmartPointer<T> &nodeItem);
BOOL updateItem(T &someItem);
void treeItems(PureVector<T> &vectoredItems)const;
void treeItems(Block<T> &blockItems)const;
void remove(void);
protected:
virtual TreeNode<T> *insertNode(TreeNode<T> *lpRootNode,TreeNode<T> *lpCurrentNode,const T &itemData);
virtual TreeNode<T> *insertNodeDuplicate(TreeNode<T> *lpRootNode,TreeNode<T> *lpCurrentNode,const T &itemData);
virtual T *searchNode(TreeNode<T> *lpRootNode,const T &someItem);
virtual TreeNode<T> *deleteBTree(TreeNode<T> *lpRootNode);
TreeNode<T> *rootNode(void)const;
TreeNode<T> *rootNode(TreeNode<T> *lpRootNode);
private:
BTree(const BTree<T> &someBTree);
BTree<T> &operator=(const BTree<T> &someBTree);
void leaves(DWORD leaves);
void remove(const T &someItem,TreeNode<T> *pCurrNode,TreeNode<T> *pParentNode);
void retrieveNodes(TreeNode<T> *lpRootNode,PureVector<T> &vectoredNodes,WORD &vectorIndex)const;
void retrieveNodes(TreeNode<T> *lpRootNode,Block<T> &blockNodes)const;
TreeNode<T> *mlpRootNode;
DWORD mLeaves;
};
template <class T>
inline
BTree<T>::BTree(void)
: mlpRootNode(0), mLeaves(0)
{
}
template <class T>
inline
BTree<T>::BTree(const BTree<T> &/*someBTree*/)
: mlpRootNode(0), mLeaves(0)
{ // private implementation
}
template <class T>
inline
BTree<T>::~BTree()
{
remove();
}
template <class T>
inline
BTree<T> &BTree<T>::operator=(const BTree<T> &/*someBTree*/)
{ // private implementation
return *this;
}
template <class T>
inline
WORD BTree<T>::insert(const T &someItem,DWORD dupsOk)
{
DWORD itemCount(leaves());
if(dupsOk)
{
if(!mlpRootNode)leaves(leaves()+(0!=(mlpRootNode=insertNodeDuplicate(mlpRootNode,mlpRootNode,someItem))));
else leaves(leaves()+(0!=insertNodeDuplicate(mlpRootNode,mlpRootNode,someItem)));
}
else
{
if(!mlpRootNode)leaves(leaves()+(0!=(mlpRootNode=insertNode(mlpRootNode,mlpRootNode,someItem))));
else leaves(leaves()+(0!=insertNode(mlpRootNode,mlpRootNode,someItem)));
}
return (!(itemCount==leaves()));
}
template <class T>
inline
BOOL BTree<T>::searchItem(T &someItem)
{
T *lpTempItem=(searchNode(mlpRootNode,someItem));
if(lpTempItem){someItem=*lpTempItem;return TRUE;}
else return FALSE;
}
template <class T>
inline
BOOL BTree<T>::searchItem(T &someItem,SmartPointer<T> &nodeItem)
{
T *lpTempItem=(searchNode(mlpRootNode,someItem));
if(lpTempItem){nodeItem=lpTempItem;return TRUE;}
return FALSE;
}
template <class T>
inline
void BTree<T>::remove(void)
{
mlpRootNode=deleteBTree(mlpRootNode);
leaves(0);
}
template <class T>
inline
TreeNode<T> *BTree<T>::rootNode(void)const
{
return mlpRootNode;
}
template <class T>
inline
TreeNode<T> *BTree<T>::rootNode(TreeNode<T> *lpRootNode)
{
remove();
return mlpRootNode=lpRootNode;
}
template <class T>
inline
DWORD BTree<T>::leaves(void)const
{
return mLeaves;
}
template <class T>
inline
void BTree<T>::leaves(DWORD leaves)
{
mLeaves=leaves;
}
#if defined(_MSC_VER)
#include <bsptree/btree.tpp>
#endif
#endif

View File

@@ -107,7 +107,8 @@ bool BTree<T>::searchNodeDuplicate(TreeNode<T> *lpRootNode,const T &someItem,Blo
} }
while(lpRootNode&&someItem==lpRootNode->item()) while(lpRootNode&&someItem==lpRootNode->item())
{ {
items.insert(&SmartPointer<T>(&lpRootNode->item())); // items.insert(&SmartPointer<T>(&lpRootNode->item()));
items.insert(new SmartPointer<T>(&lpRootNode->item()));
lpRootNode=lpRootNode->leftNode(); lpRootNode=lpRootNode->leftNode();
} }
return items.size()?true:false; return items.size()?true:false;

67
bsptree/Dictionary.hpp Normal file
View File

@@ -0,0 +1,67 @@
#ifndef _BSPTREE_DICTIONARY_HPP_
#define _BSPTREE_DICTIONARY_HPP_
#include <bsptree/btree.hpp>
#include <common/block.hpp>
template <class TKey, class TValue>
class Dictionary
{
public:
Dictionary(void);
Dictionary(const Dictionary<TKey, TValue>& someDictionary);
virtual ~Dictionary();
bool containsKey(const TKey& key);
bool insert(const TKey& key, const TValue& value);
TValue operator[](const TKey& key);
Block<TValue> getValues(void)const;
Block<TKey> getKeys(void)const;
private:
template <class TKey, class TValue>
class ItemEntry
{
public:
ItemEntry(void)
{
}
ItemEntry(const TKey& key, const TValue& value)
{
mKey = key;
mValue = value;
}
ItemEntry(const TKey& key)
{
mKey = key;
}
~ItemEntry()
{
}
int operator==(const ItemEntry<TKey, TValue>& item)const
{
return mKey == item.getKey();
}
int operator<(const ItemEntry<TKey, TValue>& item)const
{
return mKey < item.getKey();
}
int operator>(const ItemEntry<TKey, TValue>& item)const
{
return mKey > item.getKey();
}
const TKey& getKey(void)const
{
return (TKey&)mKey;
}
TValue& getValue(void)
{
return mValue;
}
private:
TKey mKey;
TValue mValue;
};
BTree<ItemEntry<TKey, TValue>> data;
};
#include <bsptree/dictionary.tpp>
#endif

80
bsptree/Dictionary.tpp Normal file
View File

@@ -0,0 +1,80 @@
#ifndef _BSPTREE_DICTIONARY_HPP_
#error DICTIONARY.HPP must precede DICTIONARY.TPP
#endif
template <class TKey, class TValue>
inline
Dictionary<TKey, TValue>::Dictionary(void)
{
}
template <class TKey, class TValue>
inline
Dictionary<TKey, TValue>::Dictionary(const Dictionary<TKey, TValue>& someDictionary)
{
throw;
}
template <class TKey, class TValue>
inline
Dictionary<TKey, TValue>::~Dictionary()
{
}
template <class TKey, class TValue>
inline
bool Dictionary<TKey, TValue>::containsKey(const TKey& key)
{
ItemEntry<TKey, TValue> item(key);
return data.find(item);
}
template <class TKey, class TValue>
inline
bool Dictionary<TKey, TValue>::insert(const TKey& key, const TValue& value)
{
ItemEntry<TKey, TValue> item(key, value);
if (data.find(item))throw;
data.insert(item);
return true;
}
template <class TKey, class TValue>
inline
Block<TValue> Dictionary<TKey, TValue>::getValues(void)const
{
Block<ItemEntry<TKey, TValue>> items = Block<ItemEntry<TKey, TValue>>();
Block<TValue> values = Block<TValue>();
data.treeItems(items);
for (int index = 0;index < items.size();index++)
{
values.insert(&items[index].getValue());
}
return values;
}
template <class TKey, class TValue>
inline
Block<TKey> Dictionary<TKey, TValue>::getKeys(void)const
{
Block<ItemEntry<TKey, TValue>> items = Block<ItemEntry<TKey, TValue>>();
Block<TKey> keys = Block<TKey>();
data.treeItems(items);
for (int index = 0;index < items.size();index++)
{
keys.insert(&items[index].getKey());
}
return keys;
}
template <class TKey, class TValue>
inline
TValue Dictionary<TKey, TValue>::operator[](const TKey& key)
{
ItemEntry<TKey, TValue> item(key);
if (!data.find(item))throw;
return item.getValue();
}
#pragma once