File: list.d

package info (click to toggle)
projectl 1.001.dfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,720 kB
  • ctags: 5
  • sloc: xml: 57; makefile: 32
file content (99 lines) | stat: -rw-r--r-- 1,383 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
module util.list;
private import util.cloneable;
template DeepList(T:Cloneable){
	class DeepList:List{
		void push_back(T t)
		{
		
			if (capacity() == size()) {
			
			int s = size()*2;
			if (s == 0) {
				s++;
			}
			T[] a = new T[s];
			for(int i=0;i<size_;++i)
				a[i] = a_[i];
				a_ = a;
			}
			a_[size_] = cast(T)t.clone();
			size_++;
	}
		void erase(int n)
		{
			for(int i=n ; i<size()-2 ; ++i){
				a_[i] = cast(T)a_[i+1].clone();
			}
			a_[--size_] = T.init; // null;
		}
	}
}
template List(T) { class List {


	T at(int n)
	{ return a_[n]; }

	int size()
	{ return size_; }

	int capacity()
	{
		if (!a_) return 0;
		return a_.length;
	}

	void erase(int n)
	{
		for(int i=n ; i<size()-2 ; ++i){
			a_[i] = a_[i+1];
		}
		a_[--size_] = T.init; // null;
	}


	void push_back(T t)
	{
	
		if (capacity() == size()) {
		
			int s = size()*2;
			if (s == 0) {
				s++;
			}
			T[] a = new T[s];
			for(int i=0;i<size_;++i)
				a[i] = a_[i];
			a_ = a;
		}
		a_[size_] = t;
		size_++;
	}

	void clear() 
	{
		size_ = 0;
		a_ = new T[16];
	}

	bool empty() 
	{	return !(a_); }

	void resize(int n)

	{
		clear();
		if (n==0) return ;
		size_ = n;

		int i=n-1,j=1;
		while (i!=0) { i>>=1; j<<=1; }
		a_ = new T[j];
	}

	this() { clear(); }

private:
	T[] a_;
	int size_;
}}