Skip to content

Commit

Permalink
rename queue to cirularqueue
Browse files Browse the repository at this point in the history
  • Loading branch information
dushibaiyu committed Apr 7, 2017
1 parent 55aed76 commit 3f72f3c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions src/yu/container/queue.d → src/yu/container/cirularqueue.d
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module yu.container.queue;
module yu.container.cirularqueue;

import core.memory;
import std.experimental.allocator.common;
import std.experimental.allocator.gc_allocator;
import std.traits;

/**
* 循环队列
Queue Struct Template.
Params:
T = the element type;
Expand All @@ -14,10 +15,10 @@ import std.traits;
Allocator = which type Allocator will used
*/

@trusted struct Queue(T, Allocator = GCAllocator, bool autoExten = false, bool addInGC = true)
@trusted struct CirularQueue(T, Allocator = GCAllocator, bool autoExten = false, bool addInGC = true)
{
enum TSize = T.sizeof;
enum addToGC = addInGC && hasIndirections!T && !is(Allocator == GCAllocator);
enum addToGC = addInGC && hasIndirections!T && !is(Unqual!Allocator == GCAllocator);
static if(hasIndirections!T)
alias InsertT = T;
else
Expand All @@ -32,10 +33,8 @@ import std.traits;
assert(size > 3);
_size = size;
_data = cast(T[]) _alloc.allocate(TSize * size);
static if (addToGC && !is(Allocator == GCAllocator))
{
static if (addToGC)
GC.addRange(_data.ptr, len);
}
}

static if (stateSize!Allocator != 0)
Expand All @@ -49,7 +48,7 @@ import std.traits;
~this()
{
if (_data.ptr) {
static if (addToGC && !is(Allocator == GCAllocator))
static if (addToGC)
GC.removeRange(_data.ptr);
_alloc.deallocate(_data);
}
Expand Down Expand Up @@ -129,7 +128,7 @@ import std.traits;
auto size = _size > 128 ? _size + ((_size / 3) * 2) : _size * 2;
auto len = TSize * size;
auto data = cast(T[]) _alloc.allocate(TSize * size);
static if (addToGC && !is(Allocator == GCAllocator))
static if (addToGC)
GC.addRange(data.ptr, len);
uint i = 0;
while (!empty)
Expand All @@ -140,7 +139,7 @@ import std.traits;
_size = size;
_front = 0;
_rear = i;
static if (addToGC && !is(Allocator == GCAllocator))
static if (addToGC)
GC.removeRange(_data.ptr);
_alloc.deallocate(_data);
_data = data;
Expand All @@ -162,7 +161,7 @@ unittest
{
import std.stdio;

auto myq = Queue!(int)(5);
auto myq = CirularQueue!(int)(5);
writeln("init is empty = ", myq.empty);
foreach (i; 0 .. 13)
{
Expand Down
2 changes: 1 addition & 1 deletion src/yu/container/vector.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import core.stdc.string : memset, memcpy;

@trusted struct Vector(T, Allocator = GCAllocator, bool addInGC = true)
{
enum addToGC = addInGC && hasIndirections!T && !is(Allocator == GCAllocator);
enum addToGC = addInGC && hasIndirections!T && !is(Unqual!Allocator == GCAllocator);

static if(hasIndirections!T)
alias InsertT = T;
Expand Down

0 comments on commit 3f72f3c

Please sign in to comment.