Click here to Skip to main content
15,895,965 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'Hanlon5-Dec-19 23:45
mvePete O'Hanlon5-Dec-19 23:45 
GeneralBe careful what you wish for Pin
CodeWraith5-Dec-19 20:39
CodeWraith5-Dec-19 20:39 
GeneralRe: Be careful what you wish for Pin
Mike Hankey5-Dec-19 20:42
mveMike Hankey5-Dec-19 20:42 
GeneralRe: Be careful what you wish for Pin
musefan5-Dec-19 21:42
musefan5-Dec-19 21:42 
GeneralWhat's one of your least favorite repeated patterns to code? Pin
honey the codewitch5-Dec-19 15:25
mvahoney the codewitch5-Dec-19 15:25 
GeneralRe: What's one of your least favorite repeated patterns to code? Pin
Super Lloyd5-Dec-19 16:42
Super Lloyd5-Dec-19 16:42 
GeneralRe: What's one of your least favorite repeated patterns to code? Pin
honey the codewitch5-Dec-19 16:53
mvahoney the codewitch5-Dec-19 16:53 
GeneralRe: What's one of your least favorite repeated patterns to code? Pin
Super Lloyd5-Dec-19 17:04
Super Lloyd5-Dec-19 17: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
C#
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
C#
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 4:14
mvahoney the codewitch6-Dec-19 4:14 
GeneralRe: What's one of your least favorite repeated patterns to code? Pin
harold aptroot5-Dec-19 22:20
harold aptroot5-Dec-19 22:20 
GeneralRe: What's one of your least favorite repeated patterns to code? Pin
honey the codewitch6-Dec-19 4:07
mvahoney the codewitch6-Dec-19 4:07 
GeneralRe: What's one of your least favorite repeated patterns to code? Pin
harold aptroot6-Dec-19 6:47
harold aptroot6-Dec-19 6:47 
GeneralRe: What's one of your least favorite repeated patterns to code? Pin
honey the codewitch6-Dec-19 12:05
mvahoney the codewitch6-Dec-19 12:05 
GeneralRe: What's one of your least favorite repeated patterns to code? Pin
Sander Rossel5-Dec-19 22:40
professionalSander Rossel5-Dec-19 22:40 
GeneralWhen there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
RedDk5-Dec-19 13:00
RedDk5-Dec-19 13:00 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
Eddy Vluggen5-Dec-19 13:49
professionalEddy Vluggen5-Dec-19 13:49 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
RedDk5-Dec-19 14:33
RedDk5-Dec-19 14:33 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
BillWoodruff5-Dec-19 16:57
professionalBillWoodruff5-Dec-19 16:57 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
Eddy Vluggen6-Dec-19 0:16
professionalEddy Vluggen6-Dec-19 0:16 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
RedDk6-Dec-19 8:07
RedDk6-Dec-19 8:07 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
Eddy Vluggen6-Dec-19 8:40
professionalEddy Vluggen6-Dec-19 8:40 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
RedDk6-Dec-19 9:28
RedDk6-Dec-19 9:28 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
Eddy Vluggen6-Dec-19 9:51
professionalEddy Vluggen6-Dec-19 9:51 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
RedDk6-Dec-19 10:04
RedDk6-Dec-19 10:04 
GeneralRe: When there's nothing on a monitor, shouldn't it go blank/ black automatically? Pin
Eddy Vluggen6-Dec-19 10:15
professionalEddy Vluggen6-Dec-19 10: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.