コード例 #1
0
        /// <summary>
        /// 加载证券
        /// </summary>
        private void Load()
        {
            //预创建内存
            m_securities.set_capacity(200);
            for (int i = 0; i < 200; i++)
            {
                CList <Security> list = new CList <Security>();
                m_securities.push_back(list);
            }
            int securitiesSize = m_securitiesCache.Count;

            int[] capacities = new int[1000];
            for (int i = 0; i < securitiesSize; i++)
            {
                Security security = m_securitiesCache[i];
                capacities[security.m_type] = capacities[security.m_type] + 1;
            }
            for (int i = 0; i < 200; i++)
            {
                CList <Security> list = m_securities.get(i);
                list.set_capacity(capacities[i]);
            }
            for (int i = 0; i < securitiesSize; i++)
            {
                Security security = m_securitiesCache[i];
                m_securities.get(security.m_type).push_back(security);
                m_securitiesMap[security.m_code.ToUpper()] = security;
            }
            m_securitiesCache.Clear();
            m_loaded   = true;
            capacities = null;
            System.GC.Collect();
        }
コード例 #2
0
        /// <summary>
        /// 查询键盘精灵
        /// </summary>
        /// <param name="key">检索值</param>
        /// <param name="limitSize">最大值</param>
        /// <param name="securities">返回键盘精灵集合</param>
        /// <returns>预留</returns>
        public int Find(String key, int limitSize, CList <Security> securities)
        {
            int order = 0, order1 = 0, order2 = 0, order3 = 0, minOrder = 0;
            int securityListSize = m_securities.size();
            CList <SecurityOrder> securityReturnList = new CList <SecurityOrder>();

            securityReturnList.set_capacity(limitSize);
            //遍历
            for (int i = 0; i < securityListSize; i++)
            {
                CList <Security> securityList = m_securities.get(i);
                int securitySize = securityList.size();
                for (int j = 0; j < securitySize; j++)
                {
                    Security security = securityList.get(j);
                    order1 = IsMatching(security.m_code, security.m_type, key, 0, i);
                    order2 = IsMatching(security.m_name, security.m_type, key, 1, i);
                    order3 = IsMatching(security.m_pingyin, security.m_type, key, 2, i);
                    order  = Math.Max(order1, Math.Max(order2, order3));
                    if (order > 0)
                    {
                        SecurityOrder securityReturn = new SecurityOrder();
                        securityReturn.m_order    = order;
                        securityReturn.m_security = security;
                        if (securityReturnList.size() < limitSize)
                        {
                            securityReturnList.push_back(securityReturn);
                        }
                        else
                        {
                            int index = 0;
                            minOrder = securityReturnList.get(0).m_order;
                            for (int m = 0; m < securityReturnList.size(); m++)
                            {
                                if (securityReturnList.get(m).m_order < minOrder)
                                {
                                    minOrder = securityReturnList.get(m).m_order;
                                    index    = m;
                                }
                            }
                            if (minOrder < order)
                            {
                                securityReturnList.get(index).m_order    = order;
                                securityReturnList.get(index).m_security = security;
                            }
                        }
                    }
                }
            }
            //排序
            int           retListSize = securityReturnList.size();
            SecurityOrder security1   = null;
            SecurityOrder security2   = null;

            for (int i = 0; i < retListSize - 1; i++)
            {
                for (int j = i + 1; j < retListSize; j++)
                {
                    security1 = securityReturnList.get(i);
                    security2 = securityReturnList.get(j);
                    if (security1.m_order < security2.m_order ||
                        (security1.m_order == security2.m_order && String.Compare(security1.m_security.m_code, security2.m_security.m_code) > 0))
                    {
                        securityReturnList.set(i, security2);
                        securityReturnList.set(j, security1);
                    }
                }
            }
            //返回
            for (int i = 0; i < retListSize; i++)
            {
                securities.push_back(securityReturnList.get(i).m_security);
            }
            securityReturnList.clear();
            return(securities.size());
        }