コード例 #1
0
 /// <summary>
 /// Adds a template to a specified location.  Replaces an existing template.
 /// </summary>
 /// <param name="template">the template value</param>
 /// <param name="templateId">the template identifier</param>
 private void AddTemplate(byte[] template, short templateId)
 {
     Debug.Assert(templateId <= compressors.Count);
     TemplateBasedCompressor ct = new TemplateBasedCompressor(templateId, template, useHuff);
     if (templateId < compressors.Count)
     {
         /*if this template is the same from before, we don't want to lose all the announcements
          * we know from before.  If we already have this exact template, it could be that someone
          * else requested it and it was broadcast to everyone.*/
         if (ct.Equals(compressors[templateId])) { return; }
         /*else we should get rid of the old and bring in the new*/
         compressors[templateId] = ct;
         return;
     }
     //we haven't seen this before, add it; throws an exception if templateId > compressors.Count
     compressors.Insert(templateId, ct);
 }
コード例 #2
0
        /// <summary>
        /// if we know a template that we would like to construct, we can give it to the Handler, 
        /// and it will add it.  
        /// </summary>
        /// <param name="template"></param>
        /// <returns></returns>
        public short ConstructTemplate(byte[] template)
        {
            // for the duration of this method, lastTemplateId is the current templateId.
            short templateId;
            lock (this)
            {
                templateId = lastTemplateId = (short)((lastTemplateId + 1) % maximumTemplates);
            }

            Debug.Assert(templateId <= compressors.Count);

            TemplateBasedCompressor ct = new TemplateBasedCompressor(templateId, template, useHuff);
            if (templateId == compressors.Count) { compressors.Add(ct); }
            else { compressors[templateId] = ct; }
            return templateId;
        }