Skip to content

Commit

Permalink
focusted test on key_comp observer
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmankoko committed Jan 10, 2024
1 parent d0c00a7 commit d120956
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
52 changes: 46 additions & 6 deletions source/stdcpp/set.d
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,16 @@ extern(C++, class) struct set(Key, compare, Alloc)
}

void swap(ref set other) nothrow;

/*
bool contains(ref const key_type key) const
{
return this._Mybase.contains(key);
}
*/
key_compare key_comp() const
{
return this._Mybase.key_comp();
}

_Tree!(_Tset_traits!(key_type,less!key_type, allocator_type, false)) _Mybase;

Expand Down Expand Up @@ -318,11 +323,13 @@ private:
extern(C++) struct _Tree_node(_value_type, _voidptr)
{
alias _Nodeptr = allocator_traits!(allocator!(_value_type)).rebind_alloc!(_Tree_node);
alias value_type = _value_type;
_Nodeptr _Left;
_Nodeptr _Parent;
_Nodeptr _Right;
char _Color;
char _Isnil;
//_value_type _Myval = value_type;

enum _Redbl {
_Red,
Expand Down Expand Up @@ -411,7 +418,11 @@ private:
}

ref inout(key_compare) _Getcomp() inout nothrow;

/*
{
return _Mypair._Get_first();
}
*/
void clear() nothrow;

size_type size() const nothrow
Expand All @@ -427,17 +438,41 @@ private:
{
return _Get_scary._Mysize == 0;
}

/*
bool contains(const ref key_type _Keyval) const
{
return _Lower_bound_duplicate(_Find_lower_bound(_Keyval)._Bound, _Keyval);
}
protected:
_Tree_find_result!(_Nodeptr) _Find_lower_bound(_Keyty)(const ref _Keyty _Keyval) const;
_Tree_find_result!(_Nodeptr) _Find_lower_bound(_Keyty)(const ref _Keyty _Keyval) const
{
const auto _Scary = _Get_scary();
_Tree_find_result!(_Nodeptr) _Result = {{_Scary._Myhead._Parent, _Tree_child._Right}, _Scary._Myhead};
_Nodeptr _Trynode = _Result._Location._Parent;
while(!_Trynode._Isnil)
{
_Result._Location._Parent = _Trynode;
if(_DEBUG_LT_PRED(_Getcomp(),_Keyval,_Traits._Kfn(_Trynode._Myval), _Keyval))
{
_Result._Location._Child = _Tree_child._Right;
_Trynode = _Trynode._Right;
}
else {
_Result._Location._Child = _Tree_child._Left;
_Result._Bound = _Trynode;
_Trynode = _Trynode._Left;
}
}
return _Result;
}
bool _Lower_bound_duplicate(_Keyty)(const _Nodeptr _Bound, ref const _Keyty _Keyval) const;
bool _Lower_bound_duplicate(_Keyty)(const _Nodeptr _Bound, ref const _Keyty _Keyval) const
{
return !_Bound._Isnil && !_DEBUG_LT_PRED(_Getcomp(), _Keyval, _Traits._Kfn(_Bound._Myval));
}
*/

public:
import stdcpp.xutility : _Compressed_pair;
Expand All @@ -452,7 +487,12 @@ private:
alias value_type = _Kty;
alias key_compare = _Pr;
alias allocator_type = _Alloc;

/*
static const ref _Kty _Kfn(const ref value_type _Val)
{
return _Val;
}
*/
}

}
2 changes: 2 additions & 0 deletions source/stdcpp/test/set.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ unittest
p.clear;
assert(p.size == 0);
assert(p.empty == 1);
assert(p.key_comp() == a);

}

0 comments on commit d120956

Please sign in to comment.