示例#1
0
        /// <summary>
        /// Union of compound number lists
        /// </summary>
        /// <param name="l2"></param>
        /// <returns></returns>

        public bool Union(
            CidList l2)
        {
            bool modified = false;

            foreach (CidListElement e in l2.List)
            {
                if (this.Get(e.Cid) != null)
                {
                    continue;                                          // if already in list then don't add
                }
                List.Add(e);
                try { Dict.Add(e.Cid, e); }
                catch (Exception ex) {}
                modified = true;
            }

            return(modified);            // todo: sort first?
        }
示例#2
0
/// <summary>
/// Apply the specified type of list logic
/// </summary>
/// <param name="l2"></param>
/// <param name="type"></param>
/// <returns></returns>

        public bool ApplyListLogic(
            CidList l2,
            ListLogicType type)
        {
            if (type == ListLogicType.Union)
            {
                return(Union(l2));
            }
            else if (type == ListLogicType.Intersect)
            {
                return(Intersect(l2));
            }
            else if (type == ListLogicType.Difference)
            {
                return(Difference(l2));
            }
            else
            {
                throw new Exception("Invalid ListLogicType: " + type);
            }
        }
示例#3
0
        /// <summary>
        /// Read a list from a file
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>

        public static CidList ReadFromFile(
            string fileName)
        {
            CidList cnList = new CidList();

            if (fileName.IndexOf(".") < 0)
            {
                fileName += ".lst";                 // append extension if needed
            }
            StreamReader sr = new StreamReader(fileName);

            while (true)
            {
                string cn = ReadCidFromFile(sr);
                if (cn == null)
                {
                    break;
                }
                cnList.Add(cn, true);                 // add allowing duplicates
            }
            sr.Close();

            return(cnList);            // return the list
        }