as tags are kept in a sorted order, a bisection is a fastest way to identify a correct position
        of or a new tag to be added. An additional check is required to make sure w don't add duplicates
494433
def add_tag(self, tag, value):
        
        index = bisect_left(self.tags, (tag, value))
        contains = False
        if index < len(self.tags):
            contains = self.tags[index] == (tag, value)
        if not contains:
            self.tags.insert(index, (tag, value))
304639
def tag(self, *tags):
        
        if any([not isinstance(tag, collections.Hashable) for tag in tags]):
            raise TypeError('Every tag should be hashable')

        if not all(isinstance(tag, collections.Hashable) for tag in tags):
            raise TypeError('Tags must be hashable')
        self.tags.update(tags)
        return self
413073
def check_item_type_uniqueness(tag, previous_tags):
    
    fail = False
    #If the tag is being created...
    if not tag.id:
        #... and the new item type is different from previous item types (for
        #example, different from the first of them), fail
        fail = previous_tags and tag.item_type != previous_tags[0].item_type
    #If the tag is being modifying...
    else:
        #... but there is only one previous tag (the one that is being
        #modifying), do not fail
        fail = previous_tags.count() > 1 and \
               tag.item_type != previous_tags[0].item_type
    return fail
872408
@SuppressWarnings("unchecked")
    public T addTag(String tag) {
        if (this.tags_ == null) {
            tags_ = new ArrayList<>();
        }
        this.tags_.add(tag);
        return (T) this;
    }
821503
void buildPT_T() {
    int numTags = tagIndex.size();
    m_TT = new double[numTags][numTags];
    m_T = new double[numTags];
    double[] tmp = new double[numTags];
    for (IntTaggedWord word : words) {
      double tot = 0.0;
      for (int t = 0; t < numTags; t++) {
        IntTaggedWord iTW = new IntTaggedWord(word.word, t);
        tmp[t] = seenCounter.getCount(iTW);
        tot += tmp[t];
      }
      if (tot < 10) {
        continue;
      }
      for (int t = 0; t < numTags; t++) {
        for (int t2 = 0; t2 < numTags; t2++) {
          if (tmp[t2] > 0.0) {
            double c = tmp[t] / tot;
            m_T[t] += c;
            m_TT[t2][t] += c;
          }
        }
      }
    }
  }
116983
public static boolean hasSisterTagAfter(Tag tag, String nameToFind) {
	Body body = (Body) tag.getParent();
	List<Statement> stats = body.getStatements();
	Iterator<Statement> it = stats.iterator();
	Statement other;

	boolean isAfter = false;
	while (it.hasNext()) {
	    other = it.next();

	    if (other instanceof Tag) {
		if (isAfter) {
		    if (((Tag) other).getTagLibTag().getName().equals(nameToFind)) return true;
		}
		else if (other == tag) isAfter = true;
	    }
	}
	return false;
    }
707506
function moveNestedTags(child, i) {
  Object.keys(child.tags).forEach(function(tagName) {
    var tag = child.tags[tagName]
    if (isArray(tag))
      each(tag, function (t) {
        moveChildTag(t, tagName, i)
      })
    else
      moveChildTag(tag, tagName, i)
  })
}
1312067
void deleteTag(long bucketIndex, int posInBucket) {
		long tagStartIdx = getTagOffset(bucketIndex, posInBucket);
		memBlock.clear(tagStartIdx, tagStartIdx + bitsPerTag);
	}
218081
void writeTagNoClear(long bucketIndex, int posInBucket, long tag) {
		long tagStartIdx = getTagOffset(bucketIndex, posInBucket);
		// BIT BANGIN YEAAAARRHHHGGGHHH
		for (int i = 0; i < bitsPerTag; i++) {
			// second arg just does bit test in tag
			if ((tag & (1L << i)) != 0) {
				memBlock.set(tagStartIdx + i);
			}
		}
	}
641804
def prefix_tag(tag)
      tag = Origen::VersionString.new(tag)
      if tag.semantic?
        tag.prefixed
      else
        tag
      end
    end
684523
private void addEntriesFromTag(List<Entry> entries, RekordboxAnlz.CueTag tag) {
        for (RekordboxAnlz.CueEntry cueEntry : tag.cues()) {  // TODO: Need to figure out how to identify deleted entries to ignore.
            if (cueEntry.type() == RekordboxAnlz.CueEntryType.LOOP) {
                entries.add(new Entry((int)cueEntry.hotCue(), Util.timeToHalfFrame(cueEntry.time()),
                        Util.timeToHalfFrame(cueEntry.loopTime())));
            } else {
                entries.add(new Entry((int)cueEntry.hotCue(), Util.timeToHalfFrame(cueEntry.time())));
            }
        }
    }
276953
private void addAdjacentSiblingElements() {
        for (Node node : nodes) {
            Node n = DOMHelper.getNextSiblingElement(node);
            if (n != null) {
                String tag = selector.getTagName();
                if (tagEquals(tag, DOMHelper.getNodeName(n)) || tag.equals(Selector.UNIVERSAL_TAG)) {
                    result.add(n);
                }
            }
        }
    }
931325
def involved_tags(self):
        """"""
        if len(self._addresses) < 2:
            # there can't be a tag boundary if there's only 1 or 0 characters
            return frozenset()

        # creating 'parent_sets' mapping, where the first item in tuple
        # is the address of character and the second is set
        # of character's parent HTML elements
        parent_sets = []

        # meanwhile we are creatingalso a set of common parents so we can
        # put them away later on (we're not interested in them as
        # they're only some global wrappers)
        common_parents = set()

        for addr in self._addresses:
            parents = set()
            if addr.attr == 'text':
                parents.add(addr.element)
            parents.update(addr.element.iterancestors())

            parent_sets.append((addr, parents))
            if not common_parents:
                common_parents = parents
            else:
                common_parents &= parents

        # constructing final set of involved tags
        involved_tags = set()
        prev_addr = None

        for addr, parents in parent_sets:
            parents = parents - common_parents
            involved_tags.update(p.tag for p in parents)

            # hidden tags - sometimes there are tags without text which
            # can hide between characters, but they actually break textflow
            is_tail_of_hidden = (
                prev_addr and
                addr.attr == 'tail' and
                prev_addr.element != addr.element
            )
            if is_tail_of_hidden:
                involved_tags.add(addr.element)

            prev_addr = addr

        return frozenset(involved_tags)
1302116
def _addTags(tags, objects):
    
    for t in tags:
        for o in objects:
            o.tags.add(t)

    return True
635922
def tagged(self, tag, offset=0, count=25):
        ''''''
        return json.loads(self.client('tag', 'get', tag, offset, count))
973158
def add_tags(new_tags)
      case new_tags
      when Array # Called with an array
        # Call recursively for each entry
        new_tags.each do |tag_hash|
          add_tags(tag_hash)
        end
      when Hash # Called with a hash
        #check if it is weird {'k' => 'key', 'v' => 'value'} syntax
        if (new_tags.size == 2 && new_tags.keys.include?('k') && new_tags.keys.include?('v'))
          # call recursively with values from k and v keys.
          add_tags({new_tags['k'] => new_tags['v']})
        else
          # OK, this seems to be a proper ruby hash with a single entry
          new_tags.each do |k,v|
            self.tags[k] = v
          end
        end
      end
      self    # return self so calls can be chained
    end
464488
@SuppressWarnings("PMD.AvoidArrayLoops")
  ArrayTagSet add(Tag tag) {
    if (length == 0) {
      return new ArrayTagSet(new String[] {tag.key(), tag.value()});
    } else {
      String[] newTags = new String[length + 2];
      String k = tag.key();
      int i = 0;
      for (; i < length && tags[i].compareTo(k) < 0; i += 2) {
        newTags[i] = tags[i];
        newTags[i + 1] = tags[i + 1];
      }
      if (i < length && tags[i].equals(k)) {
        // Override
        newTags[i++] = tag.key();
        newTags[i++] = tag.value();
        System.arraycopy(tags, i, newTags, i, length - i);
        i = length;
      } else {
        // Insert
        newTags[i] = tag.key();
        newTags[i + 1] = tag.value();
        System.arraycopy(tags, i, newTags, i + 2, length - i);
        i = newTags.length;
      }
      return new ArrayTagSet(newTags, i);
    }
  }