Skip to content

Commit

Permalink
Merge pull request #65 from Icehunter/idictionary-vs-list
Browse files Browse the repository at this point in the history
idictionary vs list
  • Loading branch information
Icehunter committed Jul 10, 2015
2 parents 7b98634 + 298502a commit 35e3c60
Show file tree
Hide file tree
Showing 17 changed files with 579 additions and 301 deletions.
67 changes: 16 additions & 51 deletions FFXIVAPP.Client/Delegates/MonsterWorkerDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
// POSSIBILITY OF SUCH DAMAGE.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Concurrent;
using FFXIVAPP.Common.Core.Memory;

namespace FFXIVAPP.Client.Delegates
Expand All @@ -38,69 +37,35 @@ public static class MonsterWorkerDelegate
{
#region Collection Access & Modification

public static void AddNPCEntity(ActorEntity entity)
public static void EnsureNPCEntity(UInt32 key, ActorEntity entity)
{
lock (_npcEntities)
{
_npcEntities.Add(entity);
}
NPCEntities.AddOrUpdate(key, entity, (k, v) => entity);
}

public static ActorEntity GetNPCEntityByName(string name)
public static ActorEntity GetNPCEntity(UInt32 key)
{
lock (_npcEntities)
{
return _npcEntities.FirstOrDefault(e => String.Equals(name, e.Name, Constants.InvariantComparer));
}
ActorEntity npc;
NPCEntities.TryGetValue(key, out npc);
return npc;
}

public static void ReplaceNPCEntities(IEnumerable<ActorEntity> entities)
public static bool RemoveNPCEntity(UInt32 key)
{
lock (_npcEntities)
{
_npcEntities = new List<ActorEntity>(entities);
}
}

public static IList<ActorEntity> GetNPCEntities()
{
lock (_npcEntities)
{
return new List<ActorEntity>(_npcEntities);
}
}

public static void AddUniqueNPCEntity(ActorEntity entity)
{
lock (_uniqueNPCEntities)
{
_uniqueNPCEntities.Add(entity);
}
}

public static void ReplaceUniqueNPCEntities(IEnumerable<ActorEntity> entities)
{
lock (_uniqueNPCEntities)
{
_uniqueNPCEntities = new List<ActorEntity>(entities);
}
}

public static IList<ActorEntity> GetUniqueNPCEntities()
{
lock (_uniqueNPCEntities)
{
return new List<ActorEntity>(_uniqueNPCEntities);
}
ActorEntity removed;
return NPCEntities.TryRemove(key, out removed);
}

#endregion

#region Declarations

private static IList<ActorEntity> _npcEntities = new List<ActorEntity>();
private static ConcurrentDictionary<UInt32, ActorEntity> _npcEntities;

private static IList<ActorEntity> _uniqueNPCEntities = new List<ActorEntity>();
public static ConcurrentDictionary<UInt32, ActorEntity> NPCEntities
{
get { return _npcEntities ?? (_npcEntities = new ConcurrentDictionary<UInt32, ActorEntity>()); }
private set { _npcEntities = value; }
}

#endregion
}
Expand Down
67 changes: 16 additions & 51 deletions FFXIVAPP.Client/Delegates/NPCWorkerDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
// POSSIBILITY OF SUCH DAMAGE.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Concurrent;
using FFXIVAPP.Common.Core.Memory;

namespace FFXIVAPP.Client.Delegates
Expand All @@ -38,69 +37,35 @@ public static class NPCWorkerDelegate
{
#region Collection Access & Modification

public static void AddNPCEntity(ActorEntity entity)
public static void EnsureNPCEntity(UInt32 key, ActorEntity entity)
{
lock (_npcEntities)
{
_npcEntities.Add(entity);
}
NPCEntities.AddOrUpdate(key, entity, (k, v) => entity);
}

public static ActorEntity GetNPCEntityByName(string name)
public static ActorEntity GetNPCEntity(UInt32 key)
{
lock (_npcEntities)
{
return _npcEntities.FirstOrDefault(e => String.Equals(name, e.Name, Constants.InvariantComparer));
}
ActorEntity npc;
NPCEntities.TryGetValue(key, out npc);
return npc;
}

public static void ReplaceNPCEntities(IEnumerable<ActorEntity> entities)
public static bool RemoveNPCEntity(UInt32 key)
{
lock (_npcEntities)
{
_npcEntities = new List<ActorEntity>(entities);
}
}

public static IList<ActorEntity> GetNPCEntities()
{
lock (_npcEntities)
{
return new List<ActorEntity>(_npcEntities);
}
}

public static void AddUniqueNPCEntity(ActorEntity entity)
{
lock (_uniqueNPCEntities)
{
_uniqueNPCEntities.Add(entity);
}
}

public static void ReplaceUniqueNPCEntities(IEnumerable<ActorEntity> entities)
{
lock (_uniqueNPCEntities)
{
_uniqueNPCEntities = new List<ActorEntity>(entities);
}
}

public static IList<ActorEntity> GetUniqueNPCEntities()
{
lock (_uniqueNPCEntities)
{
return new List<ActorEntity>(_uniqueNPCEntities);
}
ActorEntity removed;
return NPCEntities.TryRemove(key, out removed);
}

#endregion

#region Declarations

private static IList<ActorEntity> _npcEntities = new List<ActorEntity>();
private static ConcurrentDictionary<UInt32, ActorEntity> _npcEntities;

private static IList<ActorEntity> _uniqueNPCEntities = new List<ActorEntity>();
public static ConcurrentDictionary<UInt32, ActorEntity> NPCEntities
{
get { return _npcEntities ?? (_npcEntities = new ConcurrentDictionary<UInt32, ActorEntity>()); }
private set { _npcEntities = value; }
}

#endregion
}
Expand Down
66 changes: 16 additions & 50 deletions FFXIVAPP.Client/Delegates/PCWorkerDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
// POSSIBILITY OF SUCH DAMAGE.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Concurrent;
using FFXIVAPP.Common.Core.Memory;

namespace FFXIVAPP.Client.Delegates
Expand All @@ -38,69 +37,36 @@ public static class PCWorkerDelegate
{
#region Collection Access & Modification

public static void AddNPCEntity(ActorEntity entity)
public static void EnsureNPCEntity(UInt32 key, ActorEntity entity)
{
lock (_npcEntities)
{
_npcEntities.Add(entity);
}
NPCEntities.AddOrUpdate(key, entity, (k, v) => entity);
}

public static ActorEntity GetNPCEntityByName(string name)
public static ActorEntity GetNPCEntity(UInt32 key)
{
lock (_npcEntities)
{
return _npcEntities.FirstOrDefault(e => String.Equals(name, e.Name, Constants.InvariantComparer));
}
ActorEntity npc;
NPCEntities.TryGetValue(key, out npc);
return npc;
}

public static void ReplaceNPCEntities(IEnumerable<ActorEntity> entities)
public static bool RemoveNPCEntity(UInt32 key)
{
lock (_npcEntities)
{
_npcEntities = new List<ActorEntity>(entities);
}
ActorEntity removed;
return NPCEntities.TryRemove(key, out removed);
}

public static IList<ActorEntity> GetNPCEntities()
{
lock (_npcEntities)
{
return new List<ActorEntity>(_npcEntities);
}
}
#endregion

public static void AddUniqueNPCEntity(ActorEntity entity)
{
lock (_uniqueNPCEntities)
{
_uniqueNPCEntities.Add(entity);
}
}
#region Declarations

public static void ReplaceUniqueNPCEntities(IEnumerable<ActorEntity> entities)
{
lock (_uniqueNPCEntities)
{
_uniqueNPCEntities = new List<ActorEntity>(entities);
}
}
private static ConcurrentDictionary<UInt32, ActorEntity> _npcEntities;

public static IList<ActorEntity> GetUniqueNPCEntities()
public static ConcurrentDictionary<UInt32, ActorEntity> NPCEntities
{
lock (_uniqueNPCEntities)
{
return new List<ActorEntity>(_uniqueNPCEntities);
}
get { return _npcEntities ?? (_npcEntities = new ConcurrentDictionary<UInt32, ActorEntity>()); }
private set { _npcEntities = value; }
}

#endregion

#region Declarations

private static IList<ActorEntity> _npcEntities = new List<ActorEntity>();

private static IList<ActorEntity> _uniqueNPCEntities = new List<ActorEntity>();
public static ActorEntity CurrentUser { get; set; }

#endregion
Expand Down
72 changes: 72 additions & 0 deletions FFXIVAPP.Client/Delegates/PartyInfoWorkerDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// FFXIVAPP.Client
// PartyInfoWorkerDelegate.cs
//
// Copyright © 2007 - 2015 Ryan Wilson - All Rights Reserved
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of SyndicatedLife nor the names of its contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

using System;
using System.Collections.Concurrent;
using FFXIVAPP.Common.Core.Memory;

namespace FFXIVAPP.Client.Delegates
{
public static class PartyInfoWorkerDelegate
{
#region Collection Access & Modification

public static void EnsureNPCEntity(UInt32 key, PartyEntity entity)
{
NPCEntities.AddOrUpdate(key, entity, (k, v) => entity);
}

public static PartyEntity GetNPCEntity(UInt32 key)
{
PartyEntity npc;
NPCEntities.TryGetValue(key, out npc);
return npc;
}

public static bool RemoveNPCEntity(UInt32 key)
{
PartyEntity removed;
return NPCEntities.TryRemove(key, out removed);
}

#endregion

#region Declarations

private static ConcurrentDictionary<UInt32, PartyEntity> _npcEntities;

public static ConcurrentDictionary<UInt32, PartyEntity> NPCEntities
{
get { return _npcEntities ?? (_npcEntities = new ConcurrentDictionary<UInt32, PartyEntity>()); }
private set { _npcEntities = value; }
}

#endregion
}
}
1 change: 1 addition & 0 deletions FFXIVAPP.Client/FFXIVAPP.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
<DependentUpon>PluginInfoBox.xaml</DependentUpon>
</Compile>
<Compile Include="Converters\NameMultiValueConverter.cs" />
<Compile Include="Delegates\PartyInfoWorkerDelegate.cs" />
<Compile Include="Delegates\MonsterWorkerDelegate.cs" />
<Compile Include="Delegates\NPCWorkerDelegate.cs" />
<Compile Include="Delegates\PCWorkerDelegate.cs" />
Expand Down

0 comments on commit 35e3c60

Please sign in to comment.