Esempio n. 1
0
 public ForEachIterator(SQueue <V> queue)
 {
     _index   = queue._start;
     _tMark   = queue._mark;
     _tEnd    = queue._end;
     _tSize   = queue._size;
     _tValues = queue._values;
     _v       = default(V);
 }
Esempio n. 2
0
        public void init()
        {
            if (ShineSetting.messageUsePool)
            {
                _responseCacheQueue = new SQueue <BaseResponse>();
                _readStream.setDataPool(BytesControl.netDataPool);
            }

            startSocketThread();
        }
Esempio n. 3
0
        /**
         * 构造失效节点: 一个节点的失效节点所代表的字符串是该节点所表示它的字符串的最大 部分前缀
         */
        private void buildFailNode()
        {
            // 以下构造失效节点
            SQueue <DFANode> queues = new SQueue <DFANode>();

            dfaEntrance.failNode = dfaEntrance;          //

            foreach (DFANode v in dfaEntrance.dfaTransition)
            {
                v.level = 1;
                queues.offer(v);
                v.failNode = dfaEntrance;              // 失效节点指向状态机初始状态
            }
            ;

            DFANode curNode  = null;
            DFANode failNode = null;

            while (!queues.isEmpty())
            {
                curNode  = queues.poll();             // 该节点的失效节点已计算
                failNode = curNode.failNode;


                foreach (var kv in curNode.dfaTransition.entrySet())
                {
                    char    k = kv.key;
                    DFANode v = kv.value;

                    // 如果父节点的失效节点中有条相同的出边,那么失效节点就是父节点的失效节点
                    while (failNode != dfaEntrance && !failNode.dfaTransition.contains(k))
                    {
                        failNode = failNode.failNode;
                    }

                    v.failNode = failNode.dfaTransition.get(k);

                    if (v.failNode == null)
                    {
                        v.failNode = dfaEntrance;
                    }

                    v.level = curNode.level + 1;
                    queues.offer(v);                    // 计算下一层
                }
            }
        }
Esempio n. 4
0
        /** 预备下载 */
        public static int preDownLoad()
        {
            _needLoadSize = 0;
            _loadQueue    = new SQueue <ResourceSaveData>();

            _versionData.resourceDic.forEachValue(v =>
            {
                //未处理的且需要下载的部分
                if (v.state == ResourceSaveStateType.None && ResourceSaveType.needFirst(v.saveType))
                {
                    _loadQueue.offer(v);
                    _needLoadSize += v.size;
                }
            });

            return(_needLoadSize);
        }
Esempio n. 5
0
        public ObjectPool(Func <T> createFunc, int size)
        {
            _maxSize = size;

            _queue = new SQueue <T>();

            _createFunc = createFunc;

            if (ShineSetting.openCheck)
            {
                _checkSet     = new SSet <T>();
                _callStackDic = new SMap <T, string>();
            }

            if (!ShineSetting.useObjectPool)
            {
                _enable = false;
            }
        }
Esempio n. 6
0
        /** 执行一次 */
        public void runOnce()
        {
            lock (_queue)
            {
                Action <T> consumer = _consumer;
                SQueue <T> queue    = _queue;

                if (!queue.isEmpty())
                {
                    for (int i = queue.size() - 1; i >= 0; --i)
                    {
                        try
                        {
                            consumer(queue.poll());
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            throw;
                        }
                    }
                }
            }
        }