Compare commits
8 Commits
90797a48be
...
master
Author | SHA1 | Date | |
---|---|---|---|
6072bfab68
|
|||
4acf163b42 | |||
e1fd528607 | |||
1c57368f43 | |||
1c5e18b92e | |||
07b388eecb | |||
20ae6465d6 | |||
728eaf88fb
|
@ -1,6 +1,5 @@
|
||||
# Tanya
|
||||
|
||||
[](https://build.caraus.tech/go/pipelines)
|
||||
[](https://code.dlang.org/packages/tanya)
|
||||
[](https://code.dlang.org/packages/tanya)
|
||||
[](https://opensource.org/licenses/MPL-2.0)
|
||||
|
7
dub.json
7
dub.json
@ -2,7 +2,7 @@
|
||||
"name": "tanya",
|
||||
"description": "@nogc library. Containers, networking, metaprogramming, memory management, utilities",
|
||||
"license": "MPL-2.0",
|
||||
"copyright": "© Eugene Wissner <info@caraus.de>",
|
||||
"copyright": "© Eugene Wissner <belka@caraus.de>",
|
||||
"authors": [
|
||||
"Eugene Wissner"
|
||||
],
|
||||
@ -13,10 +13,7 @@
|
||||
"tanya:meta": "*",
|
||||
"tanya:os": "*",
|
||||
"tanya:middle": "*",
|
||||
"tanya:test": "*"
|
||||
},
|
||||
|
||||
"dependencies-linux": {
|
||||
"tanya:test": "*",
|
||||
"mir-linux-kernel": "~>1.0.0"
|
||||
},
|
||||
|
||||
|
@ -70,47 +70,6 @@ enum bool isWideString(T) = is(T : const dchar[]) && !isStaticArray!T;
|
||||
static assert(!isWideString!(dchar[10]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether $(D_PARAM T) is a complex type.
|
||||
*
|
||||
* Complex types are:
|
||||
* $(UL
|
||||
* $(LI cfloat)
|
||||
* $(LI ifloat)
|
||||
* $(LI cdouble)
|
||||
* $(LI idouble)
|
||||
* $(LI creal)
|
||||
* $(LI ireal)
|
||||
* )
|
||||
*
|
||||
* Params:
|
||||
* T = A type.
|
||||
*
|
||||
* Returns: $(D_KEYWORD true) if $(D_PARAM T) is a complex type,
|
||||
* $(D_KEYWORD false) otherwise.
|
||||
*/
|
||||
enum bool isComplex(T) = is(Unqual!(OriginalType!T) == cfloat)
|
||||
|| is(Unqual!(OriginalType!T) == ifloat)
|
||||
|| is(Unqual!(OriginalType!T) == cdouble)
|
||||
|| is(Unqual!(OriginalType!T) == idouble)
|
||||
|| is(Unqual!(OriginalType!T) == creal)
|
||||
|| is(Unqual!(OriginalType!T) == ireal);
|
||||
|
||||
///
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static assert(isComplex!cfloat);
|
||||
static assert(isComplex!ifloat);
|
||||
static assert(isComplex!cdouble);
|
||||
static assert(isComplex!idouble);
|
||||
static assert(isComplex!creal);
|
||||
static assert(isComplex!ireal);
|
||||
|
||||
static assert(!isComplex!float);
|
||||
static assert(!isComplex!double);
|
||||
static assert(!isComplex!real);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests whether $(D_PARAM T) is an interface.
|
||||
*
|
||||
@ -353,32 +312,6 @@ enum bool isIntegral(T) = isUnsigned!T
|
||||
static assert(!isIntegral!float);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether $(D_PARAM T) is a numeric (floating point, integral or
|
||||
* complex) type.
|
||||
*
|
||||
* Params:
|
||||
* T = A type.
|
||||
*
|
||||
* Returns: $(D_KEYWORD true) if $(D_PARAM T) is a numeric type,
|
||||
* $(D_KEYWORD false) otherwise.
|
||||
*
|
||||
* See_Also: $(D_PSYMBOL isIntegral!T),
|
||||
* $(D_PSYMBOL isFloatingPoint),
|
||||
* $(D_PSYMBOL isComplex).
|
||||
*/
|
||||
enum bool isNumeric(T) = isIntegral!T || isFloatingPoint!T || isComplex!T;
|
||||
|
||||
///
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
alias F = float;
|
||||
static assert(isNumeric!F);
|
||||
static assert(!isNumeric!bool);
|
||||
static assert(!isNumeric!char);
|
||||
static assert(!isNumeric!wchar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether $(D_PARAM T) is a boolean type, i.e. $(D_KEYWORD bool).
|
||||
*
|
||||
@ -458,67 +391,6 @@ enum bool isSomeChar(T) = is(Unqual!(OriginalType!T) == char)
|
||||
static assert(!isSomeChar!uint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether $(D_PARAM T) is a scalar type.
|
||||
*
|
||||
* Scalar types are numbers, booleans and characters.
|
||||
*
|
||||
* Params:
|
||||
* T = A type.
|
||||
*
|
||||
* Returns: $(D_KEYWORD true) if $(D_PARAM T) is a scalar type,
|
||||
* $(D_KEYWORD false) otherwise.
|
||||
*
|
||||
* See_Also: $(D_PSYMBOL isNumeric),
|
||||
* $(D_PSYMBOL isBoolean),
|
||||
* $(D_PSYMBOL isSomeChar).
|
||||
*/
|
||||
enum bool isScalarType(T) = isNumeric!T || isBoolean!T || isSomeChar!T;
|
||||
|
||||
///
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static assert(isScalarType!int);
|
||||
static assert(!isScalarType!(int[]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether $(D_PARAM T) is a basic type.
|
||||
*
|
||||
* Basic types are scalar types and $(D_KEYWORD void).
|
||||
*
|
||||
* Params:
|
||||
* T = A type.
|
||||
*
|
||||
* Returns: $(D_KEYWORD true) if $(D_PARAM T) is a basic type,
|
||||
* $(D_KEYWORD false) otherwise.
|
||||
*
|
||||
* See_Also: $(D_PSYMBOL isScalarType).
|
||||
*/
|
||||
enum bool isBasicType(T) = isScalarType!T || is(T : void);
|
||||
|
||||
///
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static struct S
|
||||
{
|
||||
}
|
||||
class C
|
||||
{
|
||||
}
|
||||
enum E : int
|
||||
{
|
||||
i = 0,
|
||||
}
|
||||
|
||||
static assert(isBasicType!void);
|
||||
static assert(isBasicType!(shared void));
|
||||
static assert(isBasicType!E);
|
||||
static assert(!isBasicType!(int*));
|
||||
static assert(!isBasicType!(void function()));
|
||||
static assert(!isBasicType!C);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether $(D_PARAM T) is a pointer type.
|
||||
*
|
||||
@ -676,34 +548,6 @@ template isAssociativeArray(T)
|
||||
static assert(!isAssociativeArray!bool);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether $(D_PARAM T) is a built-in type.
|
||||
*
|
||||
* Built-in types are all basic types and arrays.
|
||||
*
|
||||
* Params:
|
||||
* T = A type.
|
||||
*
|
||||
* Returns: $(D_KEYWORD true) if $(D_PARAM T) is a built-in type,
|
||||
* $(D_KEYWORD false) otherwise.
|
||||
*
|
||||
* See_Also: $(D_PSYMBOL isBasicType!T),
|
||||
* $(D_PSYMBOL isArray),
|
||||
* $(D_PSYMBOL isAssociativeArray).
|
||||
*/
|
||||
enum bool isBuiltinType(T) = isBasicType!T
|
||||
|| isArray!T
|
||||
|| isAssociativeArray!T;
|
||||
|
||||
///
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static assert(isBuiltinType!int);
|
||||
static assert(isBuiltinType!(int[]));
|
||||
static assert(isBuiltinType!(int[int]));
|
||||
static assert(!isBuiltinType!(int*));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether $(D_PARAM T) is an aggregate type.
|
||||
*
|
||||
@ -844,57 +688,6 @@ enum bool isSomeString(T) = isNarrowString!T || isWideString!T;
|
||||
static assert(!isSomeString!(char[10]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum value of type $(D_PARAM T). In contrast to
|
||||
* $(D_INLINECODE T.min) this template works with floating point and complex
|
||||
* types as well.
|
||||
*
|
||||
* Params:
|
||||
* T = Integral, boolean, floating point, complex or character type.
|
||||
*
|
||||
* Returns: The minimum value of $(D_PARAM T).
|
||||
*
|
||||
* See_Also: $(D_PSYMBOL isIntegral),
|
||||
* $(D_PSYMBOL isBoolean),
|
||||
* $(D_PSYMBOL isSomeChar),
|
||||
* $(D_PSYMBOL isFloatingPoint),
|
||||
* $(D_PSYMBOL isComplex).
|
||||
*/
|
||||
template mostNegative(T)
|
||||
{
|
||||
static if (isIntegral!T || isBoolean!T || isSomeChar!T)
|
||||
{
|
||||
enum T mostNegative = T.min;
|
||||
}
|
||||
else static if (isFloatingPoint!T || isComplex!T)
|
||||
{
|
||||
enum T mostNegative = -T.max;
|
||||
}
|
||||
else
|
||||
{
|
||||
static assert(false, T.stringof ~ " doesn't have the minimum value");
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static assert(mostNegative!char == char.min);
|
||||
static assert(mostNegative!wchar == wchar.min);
|
||||
static assert(mostNegative!dchar == dchar.min);
|
||||
|
||||
static assert(mostNegative!byte == byte.min);
|
||||
static assert(mostNegative!ubyte == ubyte.min);
|
||||
static assert(mostNegative!bool == bool.min);
|
||||
|
||||
static assert(mostNegative!float == -float.max);
|
||||
static assert(mostNegative!double == -double.max);
|
||||
static assert(mostNegative!real == -real.max);
|
||||
|
||||
static assert(mostNegative!ifloat == -ifloat.max);
|
||||
static assert(mostNegative!cfloat == -cfloat.max);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the type $(D_PARAM T) is copyable.
|
||||
*
|
||||
@ -2335,7 +2128,7 @@ if (isCallable!F)
|
||||
}
|
||||
else
|
||||
{
|
||||
enum getDefault(T[i .. i + 1] name)
|
||||
auto getDefault(T[i .. i + 1] name)
|
||||
{
|
||||
return name[0];
|
||||
}
|
||||
|
@ -19,13 +19,30 @@ import tanya.memory.allocator;
|
||||
import tanya.memory.op;
|
||||
import tanya.os.error;
|
||||
|
||||
extern(C) pragma(mangle, "mmap")
|
||||
private void* mapMemory(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
|
||||
@nogc nothrow pure @system;
|
||||
version (Windows)
|
||||
{
|
||||
import core.sys.windows.basetsd : SIZE_T;
|
||||
import core.sys.windows.windef : BOOL, DWORD;
|
||||
import core.sys.windows.winnt : MEM_COMMIT, MEM_RELEASE, PAGE_READWRITE, PVOID;
|
||||
|
||||
extern(C) pragma(mangle, "munmap")
|
||||
private bool unmapMemory(shared void* addr, size_t length)
|
||||
@nogc nothrow pure @system;
|
||||
extern (Windows)
|
||||
private PVOID VirtualAlloc(PVOID, SIZE_T, DWORD, DWORD)
|
||||
@nogc nothrow pure @system;
|
||||
|
||||
extern (Windows)
|
||||
private BOOL VirtualFree(shared PVOID, SIZE_T, DWORD)
|
||||
@nogc nothrow pure @system;
|
||||
}
|
||||
else
|
||||
{
|
||||
extern(C) pragma(mangle, "mmap")
|
||||
private void* mapMemory(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
|
||||
@nogc nothrow pure @system;
|
||||
|
||||
extern(C) pragma(mangle, "munmap")
|
||||
private bool unmapMemory(shared void* addr, size_t length)
|
||||
@nogc nothrow pure @system;
|
||||
}
|
||||
|
||||
/*
|
||||
* This allocator allocates memory in regions (multiple of 64 KB for example).
|
||||
@ -192,6 +209,9 @@ final class MmapPool : Allocator
|
||||
{
|
||||
block.region.next.prev = block.region.prev;
|
||||
}
|
||||
version (Windows)
|
||||
return VirtualFree(block.region, 0, MEM_RELEASE) != 0;
|
||||
else
|
||||
return unmapMemory(block.region, block.region.size) == 0;
|
||||
}
|
||||
// Merge blocks if neigbours are free.
|
||||
@ -380,6 +400,19 @@ final class MmapPool : Allocator
|
||||
{
|
||||
return null;
|
||||
}
|
||||
version (Windows)
|
||||
{
|
||||
void* p = VirtualAlloc(null,
|
||||
regionSize,
|
||||
MEM_COMMIT,
|
||||
PAGE_READWRITE);
|
||||
if (p is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
void* p = mapMemory(null,
|
||||
regionSize,
|
||||
PROT_READ | PROT_WRITE,
|
||||
@ -390,6 +423,7 @@ final class MmapPool : Allocator
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Region region = cast(Region) p;
|
||||
region.blocks = 1;
|
||||
|
@ -109,7 +109,7 @@ private struct SingletonByRef(E)
|
||||
this.element = &element;
|
||||
}
|
||||
|
||||
@property ref inout(E) front() inout return
|
||||
@property ref inout(E) front() inout return scope
|
||||
in
|
||||
{
|
||||
assert(!empty);
|
||||
@ -148,7 +148,7 @@ private struct SingletonByRef(E)
|
||||
return typeof(this)(*this.element);
|
||||
}
|
||||
|
||||
ref inout(E) opIndex(size_t i) inout return
|
||||
ref inout(E) opIndex(size_t i) inout return scope
|
||||
in
|
||||
{
|
||||
assert(!empty);
|
||||
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
module tanya.container.buffer;
|
||||
|
||||
import std.traits : isScalarType;
|
||||
import tanya.memory.allocator;
|
||||
import tanya.meta.trait;
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
*/
|
||||
module tanya.conv;
|
||||
|
||||
import std.traits : Unsigned;
|
||||
import std.traits : Unsigned, isNumeric;
|
||||
import tanya.container.string;
|
||||
import tanya.memory.allocator;
|
||||
import tanya.meta.trait;
|
||||
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
module tanya.hash.lookup;
|
||||
|
||||
import std.traits : isScalarType;
|
||||
import tanya.meta.trait;
|
||||
import tanya.range.primitive;
|
||||
|
||||
|
@ -22,8 +22,22 @@ import tanya.range;
|
||||
|
||||
version (Windows)
|
||||
{
|
||||
import tanya.sys.windows.ifdef;
|
||||
import tanya.sys.windows.iphlpapi;
|
||||
private union NET_LUID_LH { ulong Value, Info; }
|
||||
private alias NET_LUID = NET_LUID_LH;
|
||||
private alias NET_IFINDEX = uint;
|
||||
private enum IF_MAX_STRING_SIZE = 256;
|
||||
extern(Windows) @nogc nothrow private @system
|
||||
{
|
||||
uint ConvertInterfaceNameToLuidA(const(char)* InterfaceName,
|
||||
NET_LUID* InterfaceLuid);
|
||||
uint ConvertInterfaceLuidToIndex(const(NET_LUID)* InterfaceLuid,
|
||||
NET_IFINDEX* InterfaceIndex);
|
||||
uint ConvertInterfaceIndexToLuid(NET_IFINDEX InterfaceIndex,
|
||||
NET_LUID* InterfaceLuid);
|
||||
uint ConvertInterfaceLuidToNameA(const(NET_LUID)* InterfaceLuid,
|
||||
char* InterfaceName,
|
||||
size_t Length);
|
||||
}
|
||||
}
|
||||
else version (Posix)
|
||||
{
|
||||
|
Reference in New Issue
Block a user