Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: weighted container and ordered map nested iteration #414

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions msu/classes/ordered_map.nut
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
{
Array = null;
Table = null;
NextICache = null;
IIndexStack = null;

constructor( _table = null )
{
this.Array = [];
this.Table = {};
this.IIndexStack = [];
if (_table != null) this.addTable(_table);
}

Expand Down Expand Up @@ -45,10 +46,14 @@

function _nexti( _prev )
{
if (_prev == null) this.NextICache = 0;
_prev = this.NextICache++;

return _prev == this.Array.len() ? null : this.Array[_prev];
if (_prev == null) this.IIndexStack.push(0);
_prev = this.IIndexStack[this.IIndexStack.len() - 1]++;
if (_prev == this.Array.len())
{
this.IIndexStack.pop();
return null;
}
return this.Array[_prev];
}

function _cloned( _original )
Expand Down
19 changes: 11 additions & 8 deletions msu/classes/weighted_container.nut
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
Total = null;
Table = null;
Forced = null;
NextIItems = null;
NextIIndex = null;
IItems = null;
IIndexStack = null;

constructor( _array = null )
{
this.Total = 0.0;
this.Table = {};
this.Forced = [];
this.IIndexStack = [];
if (_array != null) this.addArray(_array);
}

Expand All @@ -31,19 +32,21 @@
{
if (_prev == null)
{
this.NextIItems = ::MSU.Table.keys(this.Table);
this.NextIIndex = 0;
if (this.IItems == null)
this.IItems = ::MSU.Table.keys(this.Table);
this.IIndexStack.push(0)
}
_prev = this.NextIIndex++;
_prev = this.IIndexStack[this.IIndexStack.len() - 1]++;

if (_prev == this.Table.len())
{
this.NextIItems = null;
this.NextIIndex = null;
this.IIndexStack.pop();
if (this.IIndexStack.len() == 0)
this.IItems = null;
return null;
}

return this.NextIItems[_prev];
return this.IItems[_prev];
}

function toArray( _itemsOnly = true )
Expand Down