Click here to Skip to main content
14,450,208 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: CCC (themed) (WINNER!) Pin
Pete O'Hanlon6-Dec-19 0:45
communityengineerPete O'Hanlon6-Dec-19 0:45 
GeneralBe careful what you wish for Pin
CodeWraith5-Dec-19 21:39
MemberCodeWraith5-Dec-19 21:39 
GeneralRe: Be careful what you wish for Pin
Mike Hankey5-Dec-19 21:42
professionalMike Hankey5-Dec-19 21:42 
GeneralRe: Be careful what you wish for Pin
musefan5-Dec-19 22:42
Membermusefan5-Dec-19 22:42 
GeneralWhat's one of your least favorite repeated patterns to code? Pin
honey the codewitch5-Dec-19 16:25
mvahoney the codewitch5-Dec-19 16:25 
GeneralRe: What's one of your least favorite repeated patterns to code? Pin
Super Lloyd5-Dec-19 17:42
MemberSuper Lloyd5-Dec-19 17:42 
GeneralRe: What's one of your least favorite repeated patterns to code? Pin
honey the codewitch5-Dec-19 17:53
mvahoney the codewitch5-Dec-19 17:53 
GeneralRe: What's one of your least favorite repeated patterns to code? Pin
Super Lloyd5-Dec-19 18:04
MemberSuper Lloyd5-Dec-19 18:04 
Here you go corrected version.. though I feel I might be wrong a little bit by +/- 1 on some indexes, you gotta proof read it! Poke tongue | ;-P

EDIT (oops got the count wrong on my removes... buut I still hope the general outline ispire you for its simplicity! Poke tongue | ;-P )

v1
bool ICollection<T>.Remove(T item)
{
    for(var i = 0; i < _count; ++i)
    {
        var idx = (_head + i) % _array.Length;
        if(!Equals(_array[idx],item))
            continue;

        if (_head + _count < _array.Length)
        {
            Array.Copy(_array, idx + 1, _array, idx, _count - idx - 1);
        }
        else if (idx < _head)
        {
            Array.Copy(_array, idx + 1, _array, idx, ((_head + _count) % _array.Length - idx - 1));
        }
        else
        {
            Array.Copy(_array, idx + 1, _array, idx, _array.Length - idx - 1);
            _array[_array.Length - 1] = _array[0];
            Array.Copy(_array, 1, _array, 0, _head - 1);
        }

        _array[_head + _count - 1] = default(T);
        --_count; 
        unchecked { ++_version; }
        return true;
    }
    return false;

}

v2
bool ICollection<T>.Remove(T item)
{
    var i = FindIndex(item);
    if (i == -1)
        return false;

        var idx = (_head + i) % _array.Length;
        if (_head + _count < _array.Length)
        {
            Array.Copy(_array, idx + 1, _array, idx, _count - idx - 1);
        }
        else if (idx < _head)
        {
            Array.Copy(_array, idx + 1, _array, idx, (_head - idx - 1));
        }
        else
        {
            Array.Copy(_array, idx + 1, _array, idx, _array.Length - idx - 1);
            _array[_array.Length - 1] = _array[0];
            Array.Copy(_array, 1, _array, 0, _head - 1);
        }

        _array[_head + _count - 1] = default(T);
        --_count; 
        unchecked { ++_version; }
        return true;
}
A new .NET Serializer
All in one Menu-Ribbon Bar
Taking over the world since 1371!


modified 5-Dec-19 23:11pm.

GeneralRe: What's one of your least favorite repeated patterns to code? Pin
honey the codewitch6-Dec-19 5:14
mvahoney the codewitch6-Dec-19 5:14 
GeneralRe: What's one of your least favorite repeated patterns to code? Pin
harold aptroot5-Dec-19 23:20
Memberharold aptroot5-Dec-19 23:20 
GeneralRe: What's one of your least favorite repeated patterns to code? Pin
honey the codewitch6-Dec-19 5:07
mvahoney the codewitch6-Dec-19 5:07 
GeneralRe: What's one of your least favorite repeated patterns to code? Pin
harold aptroot6-Dec-19 7:47
Memberharold aptroot6-Dec-19 7:47 
GeneralRe: What's one of your least favorite repeated patterns to code? Pin
honey the codewitch6-Dec-19 13:05
mvahoney the codewitch6-Dec-19 13:05 
GeneralRe: What's one of your least favorite repeated patterns to code? Pin
Sander Rossel5-Dec-19 23:40
professionalSander Rossel5-Dec-19 23:40 
GeneralWhen there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
RedDk5-Dec-19 14:00
MemberRedDk5-Dec-19 14:00 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
Eddy Vluggen5-Dec-19 14:49
professionalEddy Vluggen5-Dec-19 14:49 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
RedDk5-Dec-19 15:33
MemberRedDk5-Dec-19 15:33 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
BillWoodruff5-Dec-19 17:57
mveBillWoodruff5-Dec-19 17:57 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
Eddy Vluggen6-Dec-19 1:16
professionalEddy Vluggen6-Dec-19 1:16 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
RedDk6-Dec-19 9:07
MemberRedDk6-Dec-19 9:07 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
Eddy Vluggen6-Dec-19 9:40
professionalEddy Vluggen6-Dec-19 9:40 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
RedDk6-Dec-19 10:28
MemberRedDk6-Dec-19 10:28 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
Eddy Vluggen6-Dec-19 10:51
professionalEddy Vluggen6-Dec-19 10:51 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
RedDk6-Dec-19 11:04
MemberRedDk6-Dec-19 11:04 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
Eddy Vluggen6-Dec-19 11:15
professionalEddy Vluggen6-Dec-19 11:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.