Exemplo n.º 1
0
        /// <summary>
        /// Create label-ns mapping
        ///     hash of label as key, 'bitvector' of ns as value.
        /// </summary>
        /// <param name="namespaces">all namespaces.</param>
        /// <returns>label-ns mapping.</returns>
        public static Zen <IDictionary <int, IList <bool> > > CreateNSLabelMatrix(Zen <Namespace>[] namespaces)
        {
            var n = namespaces.Length;
            Dictionary <int, bool[]> labelHash = new Dictionary <int, bool[]>();

            for (int i = 0; i < n; ++i)
            {
                var keys = namespaces[i].GetLabelKeys();
                var k    = keys.Length();
                // iterate over Zen<List> to traverse all keys
                for (k -= 1; !k.EqualToNumber(ushort.MaxValue); k -= 1)
                {
                    var keyHash = keys.At(k).Value().GetHashCode();
                    if (!labelHash.ContainsKey(keyHash))
                    {
                        labelHash[keyHash] = new bool[n];
                    }
                    labelHash[keyHash][i] = true;
                }
            }
            // create zen data.
            Zen <IDictionary <int, IList <bool> > > mx = Language.EmptyDict <int, IList <bool> >();

            foreach (var kv in labelHash)
            {
                mx = mx.Add(kv.Key, kv.Value);
            }
            return(mx);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create user-pod mapping
        ///     hash of user as key, 'bitvector' of pods as value
        ///     assuming all pods have the user label.
        /// </summary>
        /// <param name="pods">all pods.</param>
        /// <param name="userKey">key of 'user label'.</param>
        /// <returns>user-pod mapping.</returns>
        public static Zen <IDictionary <int, IList <bool> > > GetUserHash(Zen <Pod>[] pods, Zen <string> userKey)
        {
            var n = pods.Length;
            Dictionary <int, bool[]> originalData = new Dictionary <int, bool[]>();

            for (int i = 0; i < n; ++i)
            {
                var labelValue = pods[i].LabelValue(userKey);
                if (labelValue == null)
                {
                    continue;
                }
                var hash = labelValue.GetHashCode();
                if (!originalData.ContainsKey(hash))
                {
                    originalData[hash] = new bool[n];
                }
                originalData[hash][i] = true;
            }
            // create zen data.
            Zen <IDictionary <int, IList <bool> > > userHashMap = EmptyDict <int, IList <bool> >();

            foreach (var kv in originalData)
            {
                userHashMap = userHashMap.Add(kv.Key, kv.Value);
            }
            return(userHashMap);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create namespace-pod mapping
        ///     hash of namespace as key, 'bitvector' of pods as value.
        /// </summary>
        /// <param name="pods">all pods.</param>
        /// <returns>namespace-pod mapping.</returns>
        public static Zen <IDictionary <int, IList <bool> > > CreateNSMatrix(Zen <Pod>[] pods)
        {
            var n = pods.Length;
            // create original data.
            Dictionary <int, bool[]> originalData = new Dictionary <int, bool[]>();

            for (int i = 0; i < n; ++i)
            {
                var ns   = pods[i].GetNS();
                var hash = ns.GetHashCode();
                if (!originalData.ContainsKey(hash))
                {
                    originalData[hash] = new bool[n];
                }
                originalData[hash][i] = true;
            }
            // create zen data.
            Zen <IDictionary <int, IList <bool> > > nsMap = Language.EmptyDict <int, IList <bool> >();

            foreach (var kv in originalData)
            {
                nsMap = nsMap.Add(kv.Key, kv.Value);
            }
            return(nsMap);
        }