Utilities for use of FacetLabel by CompactLabelToOrdinal.
        internal static int StringHashCode(CharBlockArray labelRepository, int offset)
        {
            int hash = CategoryPathUtils.HashCodeOfSerialized(labelRepository, offset);

            hash = hash ^ (((int)((uint)hash >> 20)) ^ ((int)((uint)hash >> 12)));
            hash = hash ^ ((int)((uint)hash >> 7)) ^ ((int)((uint)hash >> 4));
            return(hash);
        }
Beispiel #2
0
        internal static int StringHashCode(CharBlockArray labelRepository, int offset)
        {
            int hash = CategoryPathUtils.HashCodeOfSerialized(labelRepository, offset);

            hash = hash ^ hash.TripleShift(20) ^ hash.TripleShift(12);
            hash = hash ^ hash.TripleShift(7) ^ hash.TripleShift(4);
            return(hash);
        }
Beispiel #3
0
        internal static int StringHashCode(CharBlockArray labelRepository, int offset)
        {
            int hash = CategoryPathUtils.HashCodeOfSerialized(labelRepository, offset);

#pragma warning disable IDE0054 // Use compound assignment
            hash = hash ^ (((int)((uint)hash >> 20)) ^ ((int)((uint)hash >> 12)));
            hash = hash ^ ((int)((uint)hash >> 7)) ^ ((int)((uint)hash >> 4));
#pragma warning restore IDE0054 // Use compound assignment
            return(hash);
        }
        private void Init()
        {
            labelRepository = new CharBlockArray();
            CategoryPathUtils.Serialize(new FacetLabel(), labelRepository);

            int c = this.capacity;

            for (int i = 0; i < this.hashArrays.Length; i++)
            {
                this.hashArrays[i] = new HashArray(c);
                c /= 2;
            }
        }
        private bool AddLabel(HashArray a, FacetLabel label, int hash, int ordinal)
        {
            int index  = CompactLabelToOrdinal.IndexFor(hash, a.offsets.Length);
            int offset = a.offsets[index];

            if (offset == 0)
            {
                a.offsets[index] = this.labelRepository.Length;
                CategoryPathUtils.Serialize(label, labelRepository);
                a.cids[index] = ordinal;
                return(true);
            }

            return(false);
        }
Beispiel #6
0
        /// <summary>
        /// Return the mapping, or {@link
        ///  LabelToOrdinal#INVALID_ORDINAL} if the label isn't
        ///  recognized.
        /// </summary>
        public virtual int Get(FacetLabel label, int hash)
        {
            int   bucketIndex = IndexFor(hash, this.capacity_Renamed);
            Entry e           = this.entries[bucketIndex];

            while (e != null && !(hash == e.hash && CategoryPathUtils.EqualsToSerialized(label, labelRepository, e.offset)))
            {
                e = e.next;
            }
            if (e == null)
            {
                return(LabelToOrdinal.INVALID_ORDINAL);
            }

            return(e.cid);
        }
Beispiel #7
0
        /// <summary>
        /// Add another mapping.
        /// </summary>
        public virtual int AddLabel(FacetLabel label, int hash, int cid)
        {
            int bucketIndex = IndexFor(hash, this.capacity_Renamed);

            for (Entry e = this.entries[bucketIndex]; e != null; e = e.next)
            {
                if (e.hash == hash && CategoryPathUtils.EqualsToSerialized(label, labelRepository, e.offset))
                {
                    return(e.cid);
                }
            }

            // new string; add to label repository
            int offset = labelRepository.Length;

            CategoryPathUtils.Serialize(label, labelRepository);
            AddEntry(offset, cid, hash, bucketIndex);
            return(cid);
        }
        private int GetOrdinal(HashArray a, FacetLabel label, int hash)
        {
            if (label == null)
            {
                return(LabelToOrdinal.INVALID_ORDINAL);
            }

            int index  = IndexFor(hash, a.offsets.Length);
            int offset = a.offsets[index];

            if (offset == 0)
            {
                return(LabelToOrdinal.INVALID_ORDINAL);
            }

            if (CategoryPathUtils.EqualsToSerialized(label, labelRepository, offset))
            {
                return(a.cids[index]);
            }

            return(COLLISION);
        }