Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
475e45a
ConstOf HolderOf MutableOf added to Traits.d
Mar 2, 2013
afc0d6b
Merge remote-tracking branch 'upstream/d2port' into d2port
Mar 2, 2013
5a654b2
real is 0 bug !\?fixed
Mar 2, 2013
5963d2a
Merge remote-tracking branch 'siegelord/d2port' into d2port
Aug 13, 2013
f9addbb
In tango.util.container Slink nth(int n) change to nth(size_t n) to…
Aug 13, 2013
bb62619
False commit reverted
Aug 13, 2013
9c60ec0
False commit reverted
Aug 13, 2013
fc25d29
Merge branch 'd2port' of https://github.com/SiegeLord/Tango-D2 into d…
May 20, 2014
f7c701b
Merge branch 'siegelord' into cbleser
Apr 28, 2015
9b98da1
cbleser/d2port is now the same as siegelord/d2port
Apr 28, 2015
d59d5ee
tango/util/container/Slink.d
Apr 28, 2015
e891c85
tango/util/container/Container.d int size parameter change to size_t…
Apr 28, 2015
f84d7b0
size function in tango/util/container/RedBlack.d is now const again
Apr 28, 2015
73822e2
size function in tango/util/container/HashSet.d is now const
Apr 28, 2015
1c1bd59
size function in tango/util/container/SortedMap.d is now const
Apr 28, 2015
05d91cc
tango/util/container/more/BitSet.d
Apr 28, 2015
b29c5e3
size function in tango/util/container/more/Vector.d is now const
Apr 28, 2015
1d1e4ba
size function in tango/util/container/more/Stack.d is now const
Apr 28, 2015
cd5bb69
size function in tango/util/container/more/CacheMap.d is now const
Apr 28, 2015
56916a5
tango/util/container/more/StackMap.d
Apr 28, 2015
05878d5
size function in tango/util/container/HashMap.d is now const
Apr 28, 2015
fb98d45
tango/util/container/LinkedList.d
Apr 28, 2015
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
338 changes: 175 additions & 163 deletions tango/util/container/Container.d

Large diffs are not rendered by default.

178 changes: 89 additions & 89 deletions tango/util/container/HashMap.d

Large diffs are not rendered by default.

122 changes: 61 additions & 61 deletions tango/util/container/HashSet.d

Large diffs are not rendered by default.

84 changes: 45 additions & 39 deletions tango/util/container/LinkedList.d
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ private import tango.util.container.model.IContainer;

*******************************************************************************/

class LinkedList (V, alias Reap = Container.reap,
alias Heap = Container.DefaultCollect)
class LinkedList (V, alias Reap = Container.reap,
alias Heap = Container.DefaultCollect)
: IContainer!(V)
{
// use this type for Allocator configuration
private alias Slink!(V) Type;

private alias Type* Ref;
private alias V* VRef;

Expand All @@ -89,7 +89,7 @@ class LinkedList (V, alias Reap = Container.reap,

// configured heap manager
private Alloc heap;

// mutation tag updates on each change
private size_t mutation;

Expand Down Expand Up @@ -133,7 +133,7 @@ class LinkedList (V, alias Reap = Container.reap,
/***********************************************************************

Return a generic iterator for contained elements

***********************************************************************/

final Iterator iterator ()
Expand All @@ -151,7 +151,7 @@ class LinkedList (V, alias Reap = Container.reap,
Configure the assigned allocator with the size of each
allocation block (number of nodes allocated at one time)
and the number of nodes to pre-populate the cache with.

Time complexity: O(n)

***********************************************************************/
Expand All @@ -175,10 +175,10 @@ class LinkedList (V, alias Reap = Container.reap,
/***********************************************************************

Return the number of elements contained

***********************************************************************/

@property final const size_t size ()
@property final size_t size () const
{
return count;
}
Expand Down Expand Up @@ -237,11 +237,18 @@ class LinkedList (V, alias Reap = Container.reap,

***********************************************************************/

final V get (size_t index)
final inout(V) get (size_t index) inout
{
return cellAt(index).value;
}

alias get opIndex;
void opIndexAssign(V val, size_t index) {
addAt(index, val);
}

alias size length;

/***********************************************************************

Time complexity: O(n)
Expand Down Expand Up @@ -309,7 +316,7 @@ class LinkedList (V, alias Reap = Container.reap,
{
auto p = cellAt (from);
auto current = newlist = heap.allocate.set (p.value, null);

for (auto i = 1; i < length; ++i)
if ((p = p.next) is null)
length = i;
Expand Down Expand Up @@ -337,12 +344,12 @@ class LinkedList (V, alias Reap = Container.reap,
/***********************************************************************

Reset the HashMap contents and optionally configure a new
heap manager. We cannot guarantee to clean up reconfigured
heap manager. We cannot guarantee to clean up reconfigured
allocators, so be sure to invoke reset() before discarding
this class

Time complexity: O(n)

***********************************************************************/

final LinkedList reset ()
Expand All @@ -351,7 +358,7 @@ class LinkedList (V, alias Reap = Container.reap,
}

/***********************************************************************

Takes the first value on the list

Time complexity: O(1)
Expand Down Expand Up @@ -701,14 +708,14 @@ class LinkedList (V, alias Reap = Container.reap,

/***********************************************************************

Copy and return the contained set of values in an array,
using the optional dst as a recipient (which is resized
Copy and return the contained set of values in an array,
using the optional dst as a recipient (which is resized
as necessary).

Returns a slice of dst representing the container values.

Time complexity: O(n)

***********************************************************************/

final V[] toArray (V[] dst = null)
Expand All @@ -719,15 +726,15 @@ class LinkedList (V, alias Reap = Container.reap,
size_t i = 0;
foreach (v; this)
dst[i++] = v;
return dst [0 .. count];
return dst [0 .. count];
}

/***********************************************************************

Is this container empty?

Time complexity: O(1)

***********************************************************************/

final const bool isEmpty ()
Expand Down Expand Up @@ -793,7 +800,7 @@ class LinkedList (V, alias Reap = Container.reap,

***********************************************************************/

private Ref cellAt (size_t index)
private inout(Ref) cellAt (size_t index) inout
{
checkIndex (index);
return list.nth (index);
Expand All @@ -803,15 +810,15 @@ class LinkedList (V, alias Reap = Container.reap,

***********************************************************************/

private void checkIndex (size_t index)
private void checkIndex (size_t index) const
{
if (index >= count)
throw new Exception ("out of range");
}

/***********************************************************************

Splice elements of e between hd and tl. If hd
Splice elements of e between hd and tl. If hd
is null return new hd

Returns the count of new elements added
Expand Down Expand Up @@ -867,7 +874,7 @@ class LinkedList (V, alias Reap = Container.reap,
p = n;
}
}

list = null;
count = 0;
return this;
Expand All @@ -876,19 +883,19 @@ class LinkedList (V, alias Reap = Container.reap,
/***********************************************************************

new element was added

***********************************************************************/

private void increment ()
{
++mutation;
++count;
}

/***********************************************************************

element was removed

***********************************************************************/

private void decrement (Ref p)
Expand All @@ -898,11 +905,11 @@ class LinkedList (V, alias Reap = Container.reap,
++mutation;
--count;
}

/***********************************************************************

set was changed

***********************************************************************/

private void mutate ()
Expand Down Expand Up @@ -933,7 +940,7 @@ class LinkedList (V, alias Reap = Container.reap,
bool valid ()
{
return owner.mutation is mutation;
}
}

/***************************************************************

Expand All @@ -947,7 +954,7 @@ class LinkedList (V, alias Reap = Container.reap,
auto n = next;
return (n) ? v = *n, true : false;
}

/***************************************************************

Return a pointer to the next value, or null when
Expand Down Expand Up @@ -1037,7 +1044,7 @@ class LinkedList (V, alias Reap = Container.reap,
}
node = n;
return result;
}
}

/***************************************************************

Expand Down Expand Up @@ -1087,7 +1094,7 @@ debug (LinkedList)
foreach (value; set)
Stdout (value).newline;

// explicit generic iteration
// explicit generic iteration
foreach (value; set.iterator)
Stdout.formatln ("{}", value);

Expand All @@ -1110,7 +1117,7 @@ debug (LinkedList)
auto iterator = set.iterator;
while (iterator.next(v))
{} //iterator.remove;

// incremental iteration, with optional failfast
auto it = set.iterator;
while (it.valid && it.next(v))
Expand All @@ -1122,8 +1129,8 @@ debug (LinkedList)
// remove first element ...
while (set.take(v))
Stdout.formatln ("taking {}, {} left", v, set.size);


// setup for benchmark, with a set of integers. We
// use a chunk allocator, and presize the bucket[]
auto test = new LinkedList!(int, Container.reap, Container.Chunk);
Expand Down Expand Up @@ -1163,11 +1170,10 @@ debug (LinkedList)


// benchmark iteration
w.start;
foreach (ref iii; test) {}
w.start;
foreach (ref iii; test) {}
Stdout.formatln ("{} pointer iteration: {}/s", test.size, test.size/w.stop);

test.check;
}
}

19 changes: 7 additions & 12 deletions tango/util/container/RedBlack.d
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ struct RedBlack (V, A = AttributeDummy)
/**
* Return the number of nodes in the subtree
**/
@property size_t size ()
@property size_t size () const
{
auto c = 1;
size_t c = 1;
if (left)
c += left.size;
if (right)
Expand Down Expand Up @@ -584,12 +584,11 @@ struct RedBlack (V, A = AttributeDummy)
{
y.parent = px;
if (px !is null)
{
if (xpl)
px.left = y;
else
px.right = y;
}

x.parent = y;
if (ypl)
{
Expand All @@ -615,17 +614,15 @@ struct RedBlack (V, A = AttributeDummy)
ry.parent = x;
}
else
{
if (y is px)
{
x.parent = py;
if (py !is null)
{
if (ypl)
py.left = x;
else
py.right = x;
}

y.parent = x;
if (xpl)
{
Expand Down Expand Up @@ -654,12 +651,11 @@ struct RedBlack (V, A = AttributeDummy)
{
x.parent = py;
if (py !is null)
{
if (ypl)
py.left = x;
else
py.right = x;
}

x.left = ly;
if (ly !is null)
ly.parent = x;
Expand All @@ -670,12 +666,11 @@ struct RedBlack (V, A = AttributeDummy)

y.parent = px;
if (px !is null)
{
if (xpl)
px.left = y;
else
px.right = y;
}

y.left = lx;
if (lx !is null)
lx.parent = y;
Expand All @@ -684,7 +679,7 @@ struct RedBlack (V, A = AttributeDummy)
if (rx !is null)
rx.parent = y;
}
}

bool c = x.color;
x.color = y.color;
y.color = c;
Expand Down
Loading