it kinda work

This commit is contained in:
Milxnor
2023-04-05 07:55:28 -04:00
parent bd4a8da94f
commit 0aa6c49580
25 changed files with 1247 additions and 219 deletions

View File

@@ -30,35 +30,122 @@ public:
}
};
template <typename KeyType, typename ValueType> //, typename SetAllocator, typename KeyFuncs>
class TMapBase
template <typename KeyType, typename ValueType>
class TMap
{
public:
typedef TPair<KeyType, ValueType> ElementType;
typedef TPair<KeyType, ValueType> ElementType;
typedef TSet<ElementType/*, KeyFuncs, SetAllocator */> ElementSetType;
public:
TSet<ElementType> Pairs;
ElementSetType Pairs;
public:
class FBaseIterator
{
private:
TMap<KeyType, ValueType>& IteratedMap;
TSet<ElementType>::FBaseIterator SetIt;
public:
FBaseIterator(TMap<KeyType, ValueType>& InMap, TSet<ElementType>::FBaseIterator InSet)
: IteratedMap(InMap)
, SetIt(InSet)
{
}
FORCEINLINE TMap<KeyType, ValueType>::FBaseIterator operator++()
{
++SetIt;
return *this;
}
FORCEINLINE TMap<KeyType, ValueType>::ElementType& operator*()
{
return *SetIt;
}
FORCEINLINE const TMap<KeyType, ValueType>::ElementType& operator*() const
{
return *SetIt;
}
FORCEINLINE bool operator==(const TMap<KeyType, ValueType>::FBaseIterator& Other) const
{
return SetIt == Other.SetIt;
}
FORCEINLINE bool operator!=(const TMap<KeyType, ValueType>::FBaseIterator& Other) const
{
return SetIt != Other.SetIt;
}
FORCEINLINE bool IsElementValid() const
{
return SetIt.IsElementValid();
}
};
FORCEINLINE TMap<KeyType, ValueType>::FBaseIterator begin()
{
return TMap<KeyType, ValueType>::FBaseIterator(*this, Pairs.begin());
}
FORCEINLINE const TMap<KeyType, ValueType>::FBaseIterator begin() const
{
return TMap<KeyType, ValueType>::FBaseIterator(*this, Pairs.begin());
}
FORCEINLINE TMap<KeyType, ValueType>::FBaseIterator end()
{
return TMap<KeyType, ValueType>::FBaseIterator(*this, Pairs.end());
}
FORCEINLINE const TMap<KeyType, ValueType>::FBaseIterator end() const
{
return TMap<KeyType, ValueType>::FBaseIterator(*this, Pairs.end());
}
FORCEINLINE ValueType& operator[](const KeyType& Key)
{
return this->GetByKey(Key);
}
FORCEINLINE const ValueType& operator[](const KeyType& Key) const
{
return this->GetByKey(Key);
}
FORCEINLINE int32 Num() const
{
return Pairs.Num();
}
FORCEINLINE bool IsValid() const
{
return Pairs.IsValid();
}
FORCEINLINE bool IsIndexValid(int32 IndexToCheck) const
{
return Pairs.IsIndexValid(IndexToCheck);
}
FORCEINLINE bool Contains(const KeyType& ElementToLookFor) const
{
for (auto Element : *this)
{
if (Element.Key() == ElementToLookFor)
return true;
}
return false;
}
FORCEINLINE ValueType& GetByKey(const KeyType& Key)
{
for (auto Pair : *this)
{
if (Pair.Key() == Key)
{
return Pair.Value();
}
}
}
FORCEINLINE ValueType& Find(const KeyType& Key)
{
for (int j = 0; j < this->Pairs.Elements.Num(); j++)
return GetByKey(Key);
}
FORCEINLINE ValueType GetByKeyNoRef(const KeyType& Key)
{
for (auto Pair : *this)
{
ElementType& Pair = this->Pairs.Elements.operator[](j).ElementData.Value;
if (Key == Pair.Key())
if (Pair.Key() == Key)
{
return Pair.Value();
}
}
}
};
template <typename KeyType, typename ValueType> //, typename SetAllocator, typename KeyFuncs>
class TSortableMapBase : public TMapBase<KeyType, ValueType> //, SetAllocator, KeyFuncs>
{
};
template<typename KeyType, typename ValueType> //,typename SetAllocator /*= FDefaultSetAllocator*/, typename KeyFuncs /*= TDefaultMapHashableKeyFuncs<KeyType,ValueType,false>*/>
class TMap : public TSortableMapBase<KeyType, ValueType> //, SetAllocator, KeyFuncs>
{
}
};