From 1a42354cd2722159bb5a5b8be2f4f3fa0db05ebf Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Mon, 4 Jul 2022 02:24:00 +0700 Subject: [PATCH] Fix `HashTable` iterator not being created Messed up during converting code for `AssociativeArray`'s iterator by not paying enough attention and using old class instead of `HashTable`. --- sources/Data/Collections/HashTableIterator.uc | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/sources/Data/Collections/HashTableIterator.uc b/sources/Data/Collections/HashTableIterator.uc index 397f85c..2aba583 100644 --- a/sources/Data/Collections/HashTableIterator.uc +++ b/sources/Data/Collections/HashTableIterator.uc @@ -1,6 +1,6 @@ /** - * Iterator for iterating over `AssociativeArray`'s items. - * Copyright 2020 Anton Tarasenko + * Iterator for iterating over `HashTable`'s items. + * Copyright 2022 Anton Tarasenko *------------------------------------------------------------------------------ * This file is part of Acedia. * @@ -20,9 +20,9 @@ class HashTableIterator extends Iter dependson(HashTable); -var private bool hasNotFinished; -var private AssociativeArray relevantCollection; -var private AssociativeArray.Index currentIndex; +var private bool hasNotFinished; +var private HashTable relevantCollection; +var private HashTable.Index currentIndex; var private bool skipNoneReferences; @@ -34,17 +34,20 @@ protected function Finalizer() public function bool Initialize(Collection relevantArray) { - local AssociativeArray.Index emptyIndex; + local AcediaObject currentKey; + local HashTable.Index emptyIndex; currentIndex = emptyIndex; - relevantCollection = AssociativeArray(relevantArray); + relevantCollection = HashTable(relevantArray); if (relevantCollection == none) { return false; } hasNotFinished = (relevantCollection.GetLength() > 0); - if (GetKey() == none) { + currentKey = GetKey(); + if (currentKey == none) { relevantCollection.IncrementIndex(currentIndex); } + _.memory.Free(currentKey); return true; } @@ -66,7 +69,7 @@ public function Iter Next(optional bool deprecated) while (hasNotFinished) { hasNotFinished = relevantCollection.IncrementIndex(currentIndex); - if (relevantCollection.GetEntryByIndex(currentIndex).value != none) { + if (relevantCollection.IsSomethingByIndex(currentIndex)) { return self; } } @@ -75,12 +78,12 @@ public function Iter Next(optional bool deprecated) public function AcediaObject Get() { - return relevantCollection.GetEntryByIndex(currentIndex).value; + return relevantCollection.GetItemByIndex(currentIndex); } public function AcediaObject GetKey() { - return relevantCollection.GetEntryByIndex(currentIndex).key; + return relevantCollection.GetKeyByIndex(currentIndex); } public function bool HasFinished()