-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Improved performance for Server.
- Loading branch information
FirstGearGames
committed
Apr 4, 2024
1 parent
49f0dfc
commit de11a19
Showing
9 changed files
with
172 additions
and
157 deletions.
There are no files selected for viewing
230 changes: 115 additions & 115 deletions
230
FishNet/Plugins/Bayou/Core/BidirectionalDictionary.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,115 +1,115 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace FishNet.Transporting.Bayou | ||
{ | ||
internal class BidirectionalDictionary<T1, T2> : IEnumerable | ||
{ | ||
private Dictionary<T1, T2> t1ToT2Dict = new Dictionary<T1, T2>(); | ||
private Dictionary<T2, T1> t2ToT1Dict = new Dictionary<T2, T1>(); | ||
|
||
public IEnumerable<T1> FirstTypes => t1ToT2Dict.Keys; | ||
public IEnumerable<T2> SecondTypes => t2ToT1Dict.Keys; | ||
|
||
public IEnumerator GetEnumerator() => t1ToT2Dict.GetEnumerator(); | ||
|
||
public int Count => t1ToT2Dict.Count; | ||
|
||
public Dictionary<T1, T2> First => t1ToT2Dict; | ||
public Dictionary<T2, T1> Second => t2ToT1Dict; | ||
|
||
public void Add(T1 key, T2 value) | ||
{ | ||
if (t1ToT2Dict.ContainsKey(key)) | ||
{ | ||
Remove(key); | ||
} | ||
|
||
t1ToT2Dict[key] = value; | ||
t2ToT1Dict[value] = key; | ||
} | ||
|
||
public void Add(T2 key, T1 value) | ||
{ | ||
if (t2ToT1Dict.ContainsKey(key)) | ||
{ | ||
Remove(key); | ||
} | ||
|
||
t2ToT1Dict[key] = value; | ||
t1ToT2Dict[value] = key; | ||
} | ||
|
||
public T2 Get(T1 key) => t1ToT2Dict[key]; | ||
|
||
public T1 Get(T2 key) => t2ToT1Dict[key]; | ||
|
||
public bool TryGetValue(T1 key, out T2 value) => t1ToT2Dict.TryGetValue(key, out value); | ||
|
||
public bool TryGetValue(T2 key, out T1 value) => t2ToT1Dict.TryGetValue(key, out value); | ||
|
||
public bool Contains(T1 key) => t1ToT2Dict.ContainsKey(key); | ||
|
||
public bool Contains(T2 key) => t2ToT1Dict.ContainsKey(key); | ||
|
||
public void Remove(T1 key) | ||
{ | ||
if (First.TryGetValue(key, out T2 value)) | ||
{ | ||
t1ToT2Dict.Remove(key); | ||
t2ToT1Dict.Remove(value); | ||
} | ||
} | ||
|
||
public void Clear() | ||
{ | ||
First.Clear(); | ||
Second.Clear(); | ||
} | ||
|
||
public void Remove(T2 key) | ||
{ | ||
if (Second.TryGetValue(key, out T1 value)) | ||
{ | ||
t1ToT2Dict.Remove(value); | ||
t2ToT1Dict.Remove(key); | ||
} | ||
} | ||
|
||
public void RemoveFirst(T1 key) | ||
{ | ||
if (First.TryGetValue(key, out T2 value)) | ||
{ | ||
Second.Remove(value); | ||
First.Remove(key); | ||
} | ||
} | ||
|
||
public void RemoveSecond(T2 key) | ||
{ | ||
if (Second.TryGetValue(key, out T1 value)) | ||
{ | ||
First.Remove(value); | ||
Second.Remove(key); | ||
} | ||
} | ||
|
||
public T1 this[T2 key] | ||
{ | ||
get => t2ToT1Dict[key]; | ||
set | ||
{ | ||
Add(key, value); | ||
} | ||
} | ||
|
||
public T2 this[T1 key] | ||
{ | ||
get => t1ToT2Dict[key]; | ||
set | ||
{ | ||
Add(key, value); | ||
} | ||
} | ||
} | ||
} | ||
//using System.Collections; | ||
//using System.Collections.Generic; | ||
|
||
//namespace FishNet.Transporting.Bayou | ||
//{ | ||
// internal class BidirectionalDictionary<T1, T2> : IEnumerable | ||
// { | ||
// private Dictionary<T1, T2> t1ToT2Dict = new Dictionary<T1, T2>(); | ||
// private Dictionary<T2, T1> t2ToT1Dict = new Dictionary<T2, T1>(); | ||
|
||
// public IEnumerable<T1> FirstTypes => t1ToT2Dict.Keys; | ||
// public IEnumerable<T2> SecondTypes => t2ToT1Dict.Keys; | ||
|
||
// public IEnumerator GetEnumerator() => t1ToT2Dict.GetEnumerator(); | ||
|
||
// public int Count => t1ToT2Dict.Count; | ||
|
||
// public Dictionary<T1, T2> First => t1ToT2Dict; | ||
// public Dictionary<T2, T1> Second => t2ToT1Dict; | ||
|
||
// public void Add(T1 key, T2 value) | ||
// { | ||
// if (t1ToT2Dict.ContainsKey(key)) | ||
// { | ||
// Remove(key); | ||
// } | ||
|
||
// t1ToT2Dict[key] = value; | ||
// t2ToT1Dict[value] = key; | ||
// } | ||
|
||
// public void Add(T2 key, T1 value) | ||
// { | ||
// if (t2ToT1Dict.ContainsKey(key)) | ||
// { | ||
// Remove(key); | ||
// } | ||
|
||
// t2ToT1Dict[key] = value; | ||
// t1ToT2Dict[value] = key; | ||
// } | ||
|
||
// public T2 Get(T1 key) => t1ToT2Dict[key]; | ||
|
||
// public T1 Get(T2 key) => t2ToT1Dict[key]; | ||
|
||
// public bool TryGetValue(T1 key, out T2 value) => t1ToT2Dict.TryGetValue(key, out value); | ||
|
||
// public bool TryGetValue(T2 key, out T1 value) => t2ToT1Dict.TryGetValue(key, out value); | ||
|
||
// public bool Contains(T1 key) => t1ToT2Dict.ContainsKey(key); | ||
|
||
// public bool Contains(T2 key) => t2ToT1Dict.ContainsKey(key); | ||
|
||
// public void Remove(T1 key) | ||
// { | ||
// if (First.TryGetValue(key, out T2 value)) | ||
// { | ||
// t1ToT2Dict.Remove(key); | ||
// t2ToT1Dict.Remove(value); | ||
// } | ||
// } | ||
|
||
// public void Clear() | ||
// { | ||
// First.Clear(); | ||
// Second.Clear(); | ||
// } | ||
|
||
// public void Remove(T2 key) | ||
// { | ||
// if (Second.TryGetValue(key, out T1 value)) | ||
// { | ||
// t1ToT2Dict.Remove(value); | ||
// t2ToT1Dict.Remove(key); | ||
// } | ||
// } | ||
|
||
// public void RemoveFirst(T1 key) | ||
// { | ||
// if (First.TryGetValue(key, out T2 value)) | ||
// { | ||
// Second.Remove(value); | ||
// First.Remove(key); | ||
// } | ||
// } | ||
|
||
// public void RemoveSecond(T2 key) | ||
// { | ||
// if (Second.TryGetValue(key, out T1 value)) | ||
// { | ||
// First.Remove(value); | ||
// Second.Remove(key); | ||
// } | ||
// } | ||
|
||
// public T1 this[T2 key] | ||
// { | ||
// get => t2ToT1Dict[key]; | ||
// set | ||
// { | ||
// Add(key, value); | ||
// } | ||
// } | ||
|
||
// public T2 this[T1 key] | ||
// { | ||
// get => t1ToT2Dict[key]; | ||
// set | ||
// { | ||
// Add(key, value); | ||
// } | ||
// } | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.