diff options
author | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
commit | 6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch) | |
tree | 7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/XUtliPoolLib/SimpleQueue.cs |
+scripts
Diffstat (limited to 'Client/Assets/Scripts/XUtliPoolLib/SimpleQueue.cs')
-rw-r--r-- | Client/Assets/Scripts/XUtliPoolLib/SimpleQueue.cs | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/XUtliPoolLib/SimpleQueue.cs b/Client/Assets/Scripts/XUtliPoolLib/SimpleQueue.cs new file mode 100644 index 00000000..8781c147 --- /dev/null +++ b/Client/Assets/Scripts/XUtliPoolLib/SimpleQueue.cs @@ -0,0 +1,80 @@ +using System;
+
+namespace XUtliPoolLib
+{
+ public class SimpleQueue
+ {
+ public bool HasData
+ {
+ get
+ {
+ return this.Root != null;
+ }
+ }
+
+ private IQueueObject Root = null;
+
+ private IQueueObject Last = null;
+
+ public void Clear()
+ {
+ IQueueObject next;
+ for (IQueueObject queueObject = this.Root; queueObject != null; queueObject = next)
+ {
+ next = queueObject.next;
+ queueObject.next = null;
+ }
+ this.Root = null;
+ this.Last = null;
+ }
+
+ public void Enqueue(IQueueObject obj)
+ {
+ bool flag = obj != null;
+ if (flag)
+ {
+ obj.next = null;
+ bool flag2 = this.Root == null;
+ if (flag2)
+ {
+ this.Root = obj;
+ this.Last = this.Root;
+ }
+ else
+ {
+ bool flag3 = this.Last != null;
+ if (flag3)
+ {
+ this.Last.next = obj;
+ this.Last = obj;
+ }
+ else
+ {
+ XSingleton<XDebug>.singleton.AddErrorLog("queue state error", null, null, null, null, null);
+ }
+ }
+ }
+ else
+ {
+ XSingleton<XDebug>.singleton.AddWarningLog("can not enqueue null object", null, null, null, null, null);
+ }
+ }
+
+ public T Dequeue<T>() where T : IQueueObject, new()
+ {
+ IQueueObject queueObject = null;
+ bool flag = this.Root != null;
+ if (flag)
+ {
+ queueObject = this.Root;
+ this.Root = this.Root.next;
+ }
+ bool flag2 = this.Root == null;
+ if (flag2)
+ {
+ this.Last = null;
+ }
+ return (T)((object)queueObject);
+ }
+ }
+}
|