/// ------------------------------------------------------------------------------------ /// <summary> /// Clones this instance. /// </summary> /// ------------------------------------------------------------------------------------ public FeatureMask Clone() { FeatureMask clone = new FeatureMask(m_size); m_masks.CopyTo(clone.m_masks, 0); return(clone); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Returns a value indicating whether or not one or more features in the specified /// mask are contained within this mask instance. /// </summary> /// ------------------------------------------------------------------------------------ public bool ContainsOneOrMore(FeatureMask mask, bool throwWhenBitCountMismatch) { for (int i = 0; i < Math.Min(m_maskCount, mask.m_maskCount); i++) { if ((m_masks[i] & mask.m_masks[i]) > 0) { return(true); } } return(false); }
/// ------------------------------------------------------------------------------------ public void SetDefaultBFeatures(IEnumerable <string> featureNames) { _defaultBMask = null; if (featureNames == null) { return; } var list = featureNames.ToList(); if (list.Count > 0) { _defaultBMask = App.BFeatureCache.GetMask(list); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// ORs the the mask with the specified mask and returns a value indicating whether or /// not the bitwise AND operation yields a non-zero result. /// </summary> /// ------------------------------------------------------------------------------------ public static FeatureMask operator |(FeatureMask m1, FeatureMask m2) { if (m1.m_size != m2.m_size) { throw new ArgumentException(kBitSizeMismatchMsg); } var result = new FeatureMask(m1.m_size); for (int i = 0; i < m1.m_maskCount; i++) { result.m_masks[i] = (m1.m_masks[i] | m2.m_masks[i]); } return(result); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets an array of feature names for the features in the specified masks. /// </summary> /// ------------------------------------------------------------------------------------ public IEnumerable <string> GetFeatureList(FeatureMask mask, bool sorted) { if (mask == null) { return(new List <string>()); } var list = (from feature in Values where mask[feature.Bit] select feature.Name).ToList(); if (sorted) { list.Sort(); } return(list); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Returns a value indicating whether or not all the features in the specified mask /// are contained within this mask instance. /// </summary> /// ------------------------------------------------------------------------------------ public bool ContainsAll(FeatureMask mask) { if (m_maskCount != mask.m_maskCount) { throw new ArgumentException(kBitSizeMismatchMsg); } if (mask.IsEmpty || !mask.IsAnyBitSet) { return(false); } for (int i = 0; i < m_maskCount; i++) { if ((m_masks[i] & mask.m_masks[i]) != mask.m_masks[i]) { return(false); } } return(true); }
/// ------------------------------------------------------------------------------------ public void SetBFeatures(IEnumerable <string> featureNames) { Debug.Assert(featureNames != null); _bMask = App.BFeatureCache.GetMask(featureNames.ToList()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Returns a value indicating whether or not one or more features in the specified /// mask are contained within this mask instance. /// </summary> /// ------------------------------------------------------------------------------------ public bool ContainsOneOrMore(FeatureMask mask) { return(ContainsOneOrMore(mask, true)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets an array of sorted feature names for the features in the specified masks. /// </summary> /// ------------------------------------------------------------------------------------ public IEnumerable <string> GetFeatureList(FeatureMask mask) { return(GetFeatureList(mask, true)); }