#ifndef VCZH_COLLECTIONS_LIST
#define VCZH_COLLECTIONS_LIST
#include <string.h>
#include "Interfaces.h"
#ifdef VCZH_CHECK_MEMORY_LEAKS_NEW
#undef new
#endif
#include <new>
namespace
{
namespace
{
template
<
typename
,
bool
>
class
abstract
:
public
{
};
template
<
typename
>
class
<
,
false
>
abstract
:
public
{
protected
:
static
void
(
void
*
,
)
{
*
= (
*)
;
for
(
=
0
;
i
<
;
i
++)
{
new
(&
ds
[
i
])
();
}
}
static
void
(
void
*
,
void
*
,
)
{
*
= (
*)
;
*
= (
*)
;
for
(
=
0
;
i
<
;
i
++)
{
new
(&
ds
[
i
])
(
(
ss
[
i
]));
}
}
static
void
(
void
*
,
void
*
,
)
{
*
= (
*)
;
*
= (
*)
;
for
(
=
0
;
i
<
;
i
++)
{
new
(&
ds
[
i
])
(
ss
[
i
]);
}
}
static
void
(
void
*
,
void
*
,
)
{
*
= (
*)
;
*
= (
*)
;
if
(
ds
<
ss
)
{
for
(
=
0
;
i
<
;
i
++)
{
ds
[
i
] =
(
ss
[
i
]);
}
}
else
if
(
ds
>
ss
)
{
for
(
=
-
1
;
i
>=
0
;
i
--)
{
ds
[
i
] =
(
ss
[
i
]);
}
}
}
static
void
(
void
*
,
)
{
*
= (
*)
;
for
(
=
0
;
i
<
;
i
++)
{
ds
[
i
].~T();
}
}
static
void
*
(
)
{
if
(
<=
0
)
return
nullptr
;
return
(
void
*)
(
sizeof
(
) *
);
}
static
void
(
void
*
)
{
if
(
==
nullptr
)
return
;
(
);
}
public
:
};
template
<
typename
>
class
<
,
true
>
abstract
:
public
{
protected
:
static
void
(
void
*
,
)
{
}
static
void
(
void
*
,
void
*
,
)
{
if
(
>
0
)
{
(
,
,
sizeof
(
) *
);
}
}
static
void
(
void
*
,
void
*
,
)
{
if
(
>
0
)
{
(
,
,
sizeof
(
) *
);
}
}
static
void
(
void
*
,
void
*
,
)
{
if
(
>
0
)
{
(
,
,
sizeof
(
) *
);
}
}
static
void
(
void
*
,
)
{
}
static
void
*
(
)
{
if
(
<=
0
)
return
nullptr
;
return
(
void
*)
(
sizeof
(
) *
);
}
static
void
(
void
*
)
{
if
(
==
nullptr
)
return
;
(
);
}
public
:
};
template
<
typename
>
class
abstract
:
public
<
,
<
>::
>,
public
virtual
<
>
{
protected
:
class
:
public
,
public
virtual
<
>
{
private
:
const
<
>*
;
;
public
:
(
const
<
>*
,
= -
1
)
{
=
;
=
;
}
<
>*
()
const
override
{
return
new
(
,
);
}
const
&
()
const
override
{
return
->
(
);
}
()
const
override
{
return
;
}
bool
()
override
{
++;
return
>=
0
&&
<
->
();
}
void
()
override
{
= -
1
;
}
bool
()
const
override
{
return
true
;
}
};
void
*
=
nullptr
;
=
0
;
static
void
*
(
void
*
,
)
{
return
(
void
*)((
char
*)
+
sizeof
(
) *
);
}
const
&
(
)
const
{
return
*(
const
*)
(
,
);
}
&
(
)
{
return
*(
*)
(
,
);
}
public
:
()
{
}
<
>*
()
const
{
return
new
(
this
);
}
()
const
{
return
;
}
const
&
(
)
const
{
CHECK_ERROR(index >= 0 && index < this->count, L"ArrayBase<T, K>::Get(vint)#Argument index not in range.");
do
{
if
(!(
>=
0
&&
<
this
->
))
throw
(
L"ArrayBase<T, K>::Get(vint)#Argument index not in range."
);}
while
(
0
);
return
(
);
}
const
&
(
)
const
{
CHECK_ERROR(index >= 0 && index < this->count, L"ArrayBase<T, K>::operator[](vint)#Argument index not in range.");
do
{
if
(!(
>=
0
&&
<
this
->
))
throw
(
L"ArrayBase<T, K>::operator[](vint)#Argument index not in range."
);}
while
(
0
);
return
(
);
}
};
template
<
typename
,
typename
=
typename
<
>::
>
class
:
public
<
>
{
public
:
(
=
0
)
{
CHECK_ERROR(size >= 0, L"Array<T>::Array(vint)#Size should not be negative.");
do
{
if
(!(
>=
0
))
throw
(
L"Array<T>::Array(vint)#Size should not be negative."
);}
while
(
0
);
this
->
=
this
->
(
);
this
->
(
this
->
,
);
this
->
=
;
}
(
const
*
,
)
{
CHECK_ERROR(size >= 0, L"Array<T>::Array(const T*, vint)#Size should not be negative.");
do
{
if
(!(
>=
0
))
throw
(
L"Array<T>::Array(const T*, vint)#Size should not be negative."
);}
while
(
0
);
this
->
=
this
->
(
);
this
->
(
this
->
, (
void
*)
,
);
this
->
=
;
}
()
{
this
->
(
this
->
,
this
->
);
this
->
(
this
->
);
}
bool
(
const
&
)
const
{
return
(
) != -
1
;
}
(
const
&
)
const
{
for
(
=
0
;
i
<
this
->
;
i
++)
{
if
(
this
->
(
i
) ==
)
{
return
i
;
}
}
return
-
1
;
}
bool
(
,
const
&
)
{
CHECK_ERROR(index >= 0 && index < this->count, L"Array<T, K>::Set(vint)#Argument index not in range.");
do
{
if
(!(
>=
0
&&
<
this
->
))
throw
(
L"Array<T, K>::Set(vint)#Argument index not in range."
);}
while
(
0
);
this
->
(
) =
;
return
true
;
}
using
<
>::
;
&
(
)
{
CHECK_ERROR(index >= 0 && index < this->count, L"Array<T, K>::operator[](vint)#Argument index not in range.");
do
{
if
(!(
>=
0
&&
<
this
->
))
throw
(
L"Array<T, K>::operator[](vint)#Argument index not in range."
);}
while
(
0
);
return
this
->
(
);
}
void
(
)
{
CHECK_ERROR(size >= 0, L"Array<T>::Resize(vint)#Size should not be negative.");
do
{
if
(!(
>=
0
))
throw
(
L"Array<T>::Resize(vint)#Size should not be negative."
);}
while
(
0
);
void
*
=
this
->
(
);
if
(
<
this
->
)
{
this
->
(
this
->
(
newBuffer
,
0
),
this
->
(
this
->
,
0
),
);
}
else
{
this
->
(
this
->
(
newBuffer
,
0
),
this
->
(
this
->
,
0
),
this
->
);
this
->
(
this
->
(
newBuffer
,
this
->
),
-
this
->
);
}
this
->
(
this
->
,
this
->
);
this
->
(
this
->
);
this
->
=
newBuffer
;
this
->
=
;
}
};
template
<
typename
,
typename
=
typename
<
>::
>
class
abstract
:
public
<
>
{
protected
:
=
0
;
bool
=
false
;
(
)
{
=
;
while
(
result
<
)
{
result
=
result
*
5
/
4
+
1
;
}
return
result
;
}
void
(
,
,
bool
&
)
{
=
this
->
+
;
if
(
newCount
>
)
{
=
(
newCount
);
void
*
=
this
->
(
newCapacity
);
this
->
(
this
->
(
newBuffer
,
0
),
this
->
(
this
->
,
0
),
);
this
->
(
this
->
(
newBuffer
,
+
),
this
->
(
this
->
,
),
this
->
-
);
this
->
(
this
->
,
this
->
);
this
->
(
this
->
);
this
->
=
newCapacity
;
this
->
=
newBuffer
;
=
true
;
}
else
if
(
>=
this
->
)
{
=
true
;
}
else
if
(
this
->
-
<
)
{
this
->
(
this
->
(
this
->
,
+
),
this
->
(
this
->
,
),
this
->
-
);
this
->
(
this
->
(
this
->
,
),
- (
this
->
-
));
=
true
;
}
else
{
this
->
(
this
->
(
this
->
,
this
->
),
this
->
(
this
->
,
this
->
-
),
);
this
->
(
this
->
(
this
->
,
+
),
this
->
(
this
->
,
),
this
->
-
-
);
=
false
;
}
this
->
=
newCount
;
}
void
(
)
{
if
(
this
->
&&
this
->
<
)
{
this
->
(
this
->
(
this
->
,
this
->
),
-
this
->
);
}
if
(
this
->
&&
this
->
<=
this
->
/
2
)
{
=
*
5
/
8
;
if
(
this
->
<
newCapacity
)
{
void
*
=
this
->
(
newCapacity
);
this
->
(
this
->
(
newBuffer
,
0
),
this
->
(
this
->
,
0
),
this
->
);
this
->
(
this
->
,
this
->
);
this
->
(
this
->
);
this
->
=
newCapacity
;
this
->
=
newBuffer
;
}
}
}
public
:
()
{
}
()
{
this
->
(
this
->
,
this
->
);
this
->
(
this
->
);
}
void
(
bool
)
{
this
->
=
;
}
bool
(
)
{
=
this
->
;
CHECK_ERROR(index >= 0 && index < this->count, L"ListBase<T, K>::RemoveAt(vint)#Argument index not in range.");
do
{
if
(!(
>=
0
&&
<
this
->
))
throw
(
L"ListBase<T, K>::RemoveAt(vint)#Argument index not in range."
);}
while
(
0
);
this
->
(
this
->
(
this
->
,
),
this
->
(
this
->
,
+
1
),
this
->
-
-
1
);
this
->
--;
(
previousCount
);
return
true
;
}
bool
(
,
)
{
=
this
->
;
CHECK_ERROR(index >= 0 && index <= this->count, L"ListBase<T, K>::RemoveRange(vint, vint)#Argument index not in range.");
do
{
if
(!(
>=
0
&&
<=
this
->
))
throw
(
L"ListBase<T, K>::RemoveRange(vint, vint)#Argument index not in range."
);}
while
(
0
);
CHECK_ERROR(index + _count >= 0 && index + _count <= this->count, L"ListBase<T,K>::RemoveRange(vint, vint)#Argument _count not in range.");
do
{
if
(!(
+
>=
0
&&
+
<=
this
->
))
throw
(
L"ListBase<T,K>::RemoveRange(vint, vint)#Argument _count not in range."
);}
while
(
0
);
this
->
(
this
->
(
this
->
,
),
this
->
(
this
->
,
+
),
this
->
-
-
);
this
->
-=
;
(
previousCount
);
return
true
;
}
bool
()
{
=
this
->
;
this
->
=
0
;
if
(
)
{
this
->
=
0
;
this
->
(
this
->
,
this
->
);
this
->
(
this
->
);
this
->
=
nullptr
;
}
else
{
(
previousCount
);
}
return
true
;
}
};
template
<
typename
,
typename
=
typename
<
>::
>
class
:
public
<
,
>
{
public
:
() =
default
;
bool
(
const
&
)
const
{
return
(
) != -
1
;
}
(
const
&
)
const
{
for
(
=
0
;
i
<
this
->
;
i
++)
{
if
(
this
->
(
i
) ==
)
{
return
i
;
}
}
return
-
1
;
}
(
const
&
)
{
return
(
this
->
,
);
}
(
,
const
&
)
{
CHECK_ERROR(index >= 0 && index <= this->count, L"List<T, K>::Insert(vint, const T&)#Argument index not in range.");
do
{
if
(!(
>=
0
&&
<=
this
->
))
throw
(
L"List<T, K>::Insert(vint, const T&)#Argument index not in range."
);}
while
(
0
);
bool
=
false
;
this
->
(
,
1
,
uninitialized
);
if
(
uninitialized
)
{
new
(&
this
->
(
))
(
);
}
else
{
this
->
(
) =
;
}
return
;
}
bool
(
const
&
)
{
=
(
);
if
(
index
>=
0
&&
index
<
this
->
)
{
this
->
(
index
);
return
true
;
}
else
{
return
false
;
}
}
bool
(
,
const
&
)
{
CHECK_ERROR(index >= 0 && index < this->count, L"List<T, K>::Set(vint)#Argument index not in range.");
do
{
if
(!(
>=
0
&&
<
this
->
))
throw
(
L"List<T, K>::Set(vint)#Argument index not in range."
);}
while
(
0
);
this
->
(
) =
;
return
true
;
}
using
<
,
>::
;
&
(
)
{
CHECK_ERROR(index >= 0 && index < this->count, L"List<T, K>::operator[](vint)#Argument index not in range.");
do
{
if
(!(
>=
0
&&
<
this
->
))
throw
(
L"List<T, K>::operator[](vint)#Argument index not in range."
);}
while
(
0
);
return
this
->
(
);
}
};
template
<
typename
,
typename
=
typename
<
>::
>
class
:
public
<
,
>
{
protected
:
template
<
typename
>
(
const
&
,
&
)
const
{
=
0
;
=
this
->
-
1
;
= -
1
;
while
(
start
<=
end
)
{
=
start
+ (
end
-
start
) /
2
;
if
(
this
->
(
) ==
)
{
return
;
}
else
if
(
this
->
(
) >
)
{
end
=
-
1
;
}
else
{
start
=
+
1
;
}
}
return
-
1
;
}
(
,
const
&
)
{
bool
=
false
;
this
->
(
,
1
,
uninitialized
);
if
(
uninitialized
)
{
new
(&
this
->
(
))
(
);
}
else
{
this
->
(
) =
;
}
return
;
}
public
:
() =
default
;
bool
(
const
&
)
const
{
return
(
) != -
1
;
}
(
const
&
)
const
{
= -
1
;
return
<
>(
,
outputIndex
);
}
(
const
&
)
{
if
(
<
>::
==
0
)
{
return
(
0
,
);
}
else
{
= -
1
;
<
>(
,
outputIndex
);
CHECK_ERROR(outputIndex >= 0 && outputIndex < this->count, L"SortedList<T, K>::Add(const T&)#Internal error, index not in range.");
do
{
if
(!(
outputIndex
>=
0
&&
outputIndex
<
this
->
))
throw
(
L"SortedList<T, K>::Add(const T&)#Internal error, index not in range."
);}
while
(
0
);
if
(
this
->
(
outputIndex
) <
)
{
outputIndex
++;
}
return
(
outputIndex
,
);
}
}
bool
(
const
&
)
{
=
(
);
if
(
index
>=
0
&&
index
<
<
>::
)
{
this
->
(
index
);
return
true
;
}
else
{
return
false
;
}
}
};
template
<
typename
>
class
:
public
,
private
{
protected
:
;
;
<
*>
;
public
:
(
=
65536
)
:blockSize(
)
, allocatedSize(
0
)
{
}
()
{
for
(
=
0
;
i
<
.
();
i
++)
{
delete
[]
i
];
}
}
*
(
)
{
if
(
>=
)
{
return
0
;
}
=
/
;
=
%
;
return
&
row
][
column
];
}
*
()
{
if
(
==
.
()*
)
{
.
(
new
[
]);
}
=
++;
return
(
index
);
}
};
namespace
{
struct
{
*
[
4
];
};
template
<
=
4
>
struct
{
static
__forceinline
void
*
(
*
,
)
{
if
(!
)
{
return
nullptr
;
}
= (
>> (
2
* (
-
1
))) %
4
;
*
=
->
[
fragmentIndex
];
return
fragmentRoot
?
<
-
1
>::
(
fragmentRoot
,
) :
0
;
}
static
__forceinline
void
(
*&
,
,
void
*
,
<
>&
)
{
if
(!
)
{
=
.
();
(
->
,
0
,
sizeof
(
->
));
}
= (
>> (
2
* (
-
1
))) %
4
;
*&
=
->
[
fragmentIndex
];
<
-
1
>::
(
fragmentRoot
,
,
,
);
}
};
template
<>
struct
<
0
>
{
static
__forceinline
void
*
(
*
,
)
{
return
(
void
*)
;
}
static
__forceinline
void
(
*&
,
,
void
*
,
<
>&
)
{
((
void
*&)
) =
;
}
};
}
template
<
typename
>
class
:
public
,
private
{
public
:
typedef
<
bom_helper
::
>
;
protected
:
bom_helper
::
*
=
nullptr
;
public
:
() =
default
;
() =
default
;
*
(
)
{
return
(
*)
bom_helper
::
<>::
(
,
);
}
void
(
,
*
,
&
)
{
bom_helper
::
<>::
(
,
,
,
);
}
};
namespace
{
template
<
typename
,
typename
>
struct
<
<
,
>>
{
static
const
bool
=
true
;
static
const
bool
=
true
;
};
template
<
typename
,
typename
>
struct
<
<
,
>>
{
static
const
bool
=
true
;
static
const
bool
=
false
;
};
template
<
typename
,
typename
>
struct
<
<
,
>>
{
static
const
bool
=
true
;
static
const
bool
=
false
;
};
}
}
}
#ifdef VCZH_CHECK_MEMORY_LEAKS_NEW
#define new VCZH_CHECK_MEMORY_LEAKS_NEW
#endif
#endif