Flip colors of a node and its children.
163106
def flip(self):
        

        left = self.left._replace(red=not self.left.red)
        right = self.right._replace(red=not self.right.red)
        top = self._replace(left=left, right=right, red=not self.red)
        return top
522974
private RedBlackTreeNode<Key, Value> balance(RedBlackTreeNode<Key, Value> h) {
	// assert (h != null);

	if (isRed(h.getRight()))
	    h = rotateLeft(h);
	if (isRed(h.getLeft()) && isRed(h.getLeft().getLeft()))
	    h = rotateRight(h);
	if (isRed(h.getLeft()) && isRed(h.getRight()))
	    flipColors(h);

	h.setSize(size(h.getLeft()) + size(h.getRight()) + 1);
	return h;
    }
982678
function(parentNode, reverse, ofType) {
      parentNode._counted = true;
      if (reverse) {
        for (var nodes = parentNode.childNodes, i = nodes.length - 1, j = 1; i >= 0; i--) {
          var node = nodes[i];
          if (node.nodeType == 1 && (!ofType || node._counted)) node.nodeIndex = j++;
        }
      } else {
        for (var i = 0, j = 1, nodes = parentNode.childNodes; node = nodes[i]; i++)
          if (node.nodeType == 1 && (!ofType || node._counted)) node.nodeIndex = j++;
      }
    }
935490
private Node rotateRight(Node node) {
        Node rightChild = node.right;
        node.right = rightChild.left;
        rightChild.left = node;
        node.height = calculateHeight(getHeight(node.left), getHeight(node.right));
        rightChild.height = calculateHeight(getHeight(rightChild.right), node.height);
        return rightChild;
    }
404446
private void swap(Node n, Node p, Node pp) {
        if (pp == null) {
            swap(n, p);
            return;
        }

        Node nLeftChild = n.o_c;
        if (pp.o_c == p) {
            // p left child of pp
            if (p.o_c == n) {
                if (n.y_s == p) {
                    // n left child of p and no sibling
                    pp.o_c = n;
                    n.y_s = p.y_s;
                    n.o_c = p;
                    p.y_s = n;
                } else {
                    // n left child or p and sibling
                    n.y_s.y_s = n;
                    Node tmp = n.y_s;
                    n.y_s = p.y_s;
                    p.y_s = tmp;
                    pp.o_c = n;
                    n.o_c = p;
                }
            } else {
                // n right child of p
                Node tmp = p.o_c;
                n.y_s = p.y_s;
                pp.o_c = n;
                n.o_c = tmp;
                tmp.y_s = p;
                p.y_s = n;
            }
        } else {
            // p right child of pp
            if (p.o_c == n) {
                if (n.y_s == p) {
                    // n left child of p and no sibling
                    n.y_s = pp;
                    pp.o_c.y_s = n;
                    n.o_c = p;
                    p.y_s = n;
                } else {
                    // n left child of p and sibling
                    pp.o_c.y_s = n;
                    p.y_s = n.y_s;
                    n.y_s = pp;
                    n.o_c = p;
                    p.y_s.y_s = n;
                }
            } else {
                // n right child of p
                pp.o_c.y_s = n;
                n.y_s = pp;
                n.o_c = p.o_c;
                n.o_c.y_s = p;
                p.y_s = n;
            }
        }

        // hang children
        p.o_c = nLeftChild;
        if (nLeftChild != null) {
            if (nLeftChild.y_s == n) {
                nLeftChild.y_s = p;
            } else {
                nLeftChild.y_s.y_s = p;
            }
        }
    }
1153376
def compute_group_colors(self):
        """"""
        seen = set()
        self.group_label_color = [
            x for x in self.node_colors if not (x in seen or seen.add(x))
        ]
804084
def reverse_color(moves)
      moves.each do |move|
        if move["move"] && move["move"]["color"]
          move["move"]["color"] = (move["move"]["color"] + 1) % 2
        end
        move["forks"].each { |_fork| reverse_color(_fork) } if move["forks"]
      end
    end
624712
function ( type, settings, parent, colors ) {

        T.dom( type, null, settings, parent, 0 );

        var n = parent.childNodes[0].childNodes.length - 1, c;

        for( var i = 0; i < colors.length; i++ ){

            c = colors[i];
            T.dom( 'stop', null, { offset:c[0]+'%', style:'stop-color:'+c[1]+'; stop-opacity:'+c[2]+';' }, parent, [0,n] );

        }

    }
370194
public void flip(int x, int y) {
    int offset = y * rowSize + (x / 32);
    bits[offset] ^= 1 << (x & 0x1f);
  }
227402
def _invert(color):
    
    col = ColorValue(color)
    c = col.value
    c[0] = 255.0 - c[0]
    c[1] = 255.0 - c[1]
    c[2] = 255.0 - c[2]
    return col
351333
def BrushForNode( self, node, depth=0 ):
        """"""
        if node == self.selectedNode:
            color = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT)
        elif node == self.highlightedNode:
            color = wx.Colour( red=0, green=255, blue=0 )
        else:
            color = self.adapter.background_color(node, depth)
            if not color:
                red = (depth * 10)%255
                green = 255-((depth * 5)%255)
                blue = (depth * 25)%255
                color = wx.Colour( red, green, blue )
        return wx.Brush( color  )
132909
function fixDoubleBlack(stack) {
  var n, p, s, z
  for(var i=stack.length-1; i>=0; --i) {
    n = stack[i]
    if(i === 0) {
      n._color = BLACK
      return
    }
    //console.log("visit node:", n.key, i, stack[i].key, stack[i-1].key)
    p = stack[i-1]
    if(p.left === n) {
      //console.log("left child")
      s = p.right
      if(s.right && s.right._color === RED) {
        //console.log("case 1: right sibling child red")
        s = p.right = cloneNode(s)
        z = s.right = cloneNode(s.right)
        p.right = s.left
        s.left = p
        s.right = z
        s._color = p._color
        n._color = BLACK
        p._color = BLACK
        z._color = BLACK
        recount(p)
        recount(s)
        if(i > 1) {
          var pp = stack[i-2]
          if(pp.left === p) {
            pp.left = s
          } else {
            pp.right = s
          }
        }
        stack[i-1] = s
        return
      } else if(s.left && s.left._color === RED) {
        //console.log("case 1: left sibling child red")
        s = p.right = cloneNode(s)
        z = s.left = cloneNode(s.left)
        p.right = z.left
        s.left = z.right
        z.left = p
        z.right = s
        z._color = p._color
        p._color = BLACK
        s._color = BLACK
        n._color = BLACK
        recount(p)
        recount(s)
        recount(z)
        if(i > 1) {
          var pp = stack[i-2]
          if(pp.left === p) {
            pp.left = z
          } else {
            pp.right = z
          }
        }
        stack[i-1] = z
        return
      }
      if(s._color === BLACK) {
        if(p._color === RED) {
          //console.log("case 2: black sibling, red parent", p.right.value)
          p._color = BLACK
          p.right = repaint(RED, s)
          return
        } else {
          //console.log("case 2: black sibling, black parent", p.right.value)
          p.right = repaint(RED, s)
          continue  
        }
      } else {
        //console.log("case 3: red sibling")
        s = cloneNode(s)
        p.right = s.left
        s.left = p
        s._color = p._color
        p._color = RED
        recount(p)
        recount(s)
        if(i > 1) {
          var pp = stack[i-2]
          if(pp.left === p) {
            pp.left = s
          } else {
            pp.right = s
          }
        }
        stack[i-1] = s
        stack[i] = p
        if(i+1 < stack.length) {
          stack[i+1] = n
        } else {
          stack.push(n)
        }
        i = i+2
      }
    } else {
      //console.log("right child")
      s = p.left
      if(s.left && s.left._color === RED) {
        //console.log("case 1: left sibling child red", p.value, p._color)
        s = p.left = cloneNode(s)
        z = s.left = cloneNode(s.left)
        p.left = s.right
        s.right = p
        s.left = z
        s._color = p._color
        n._color = BLACK
        p._color = BLACK
        z._color = BLACK
        recount(p)
        recount(s)
        if(i > 1) {
          var pp = stack[i-2]
          if(pp.right === p) {
            pp.right = s
          } else {
            pp.left = s
          }
        }
        stack[i-1] = s
        return
      } else if(s.right && s.right._color === RED) {
        //console.log("case 1: right sibling child red")
        s = p.left = cloneNode(s)
        z = s.right = cloneNode(s.right)
        p.left = z.right
        s.right = z.left
        z.right = p
        z.left = s
        z._color = p._color
        p._color = BLACK
        s._color = BLACK
        n._color = BLACK
        recount(p)
        recount(s)
        recount(z)
        if(i > 1) {
          var pp = stack[i-2]
          if(pp.right === p) {
            pp.right = z
          } else {
            pp.left = z
          }
        }
        stack[i-1] = z
        return
      }
      if(s._color === BLACK) {
        if(p._color === RED) {
          //console.log("case 2: black sibling, red parent")
          p._color = BLACK
          p.left = repaint(RED, s)
          return
        } else {
          //console.log("case 2: black sibling, black parent")
          p.left = repaint(RED, s)
          continue  
        }
      } else {
        //console.log("case 3: red sibling")
        s = cloneNode(s)
        p.left = s.right
        s.right = p
        s._color = p._color
        p._color = RED
        recount(p)
        recount(s)
        if(i > 1) {
          var pp = stack[i-2]
          if(pp.right === p) {
            pp.right = s
          } else {
            pp.left = s
          }
        }
        stack[i-1] = s
        stack[i] = p
        if(i+1 < stack.length) {
          stack[i+1] = n
        } else {
          stack.push(n)
        }
        i = i+2
      }
    }
  }
}
172137
private void cascadingCut(Node<K, V> y) {
        Node<K, V> z;
        while ((z = y.parent) != null) {
            if (!y.mark) {
                y.mark = true;
                break;
            }
            cut(y, z);
            y = z;
        }
    }
810777
def background_color(self, node, depth):
        """"""
        if self.color_mapping is None:
            self.color_mapping = {}
        color = self.color_mapping.get(node.key)
        if color is None:
            depth = len(self.color_mapping)
            red = (depth * 10) % 255
            green = 200 - ((depth * 5) % 200)
            blue = (depth * 25) % 200
            self.color_mapping[node.key] = color = wx.Colour(red, green, blue)
        return color
105637
function(env, op, other) {
        var result = [],
            rgb2;

        if (other instanceof tree.Color) {
            rgb2 = chroma(other.toString()).rgb();
        }
        else if (_.isArray(other)) {
            rgb2 = _.slice(other, 0, Math.max(other.length, 3));
        }
        else if (_.isObject(other)) {
            if (_.has(other, 'value')) {
                rgb2 = [other.value, other.value, other.value];
            }
            else {
                return;
            }
        }
        else {
            rgb2 = [other, other, other];
        }

        var rgb1 = chroma(this.toString()).rgb();

        for (var c = 0; c < 3; c++) {
            result[c] = tree.operate(op, rgb1[c] , rgb2[c]);
        }

        if (this.perceptual) {
            var normalize = function (x) {
                return x / 255;
            };
            result = hsluv.rgbToHsluv(_.map(result, normalize));
            result[1] = result[1] / 100;
            result[2] = result[2] / 100;
        }
        else {
            result = chroma(result).hsl();
        }

        return new tree.Color(result, this.alpha, this.perceptual);
    }
300551
function flipImageData (data, width, height) {
  const numComponents = data.length / (width * height)
  for (let y = 0; y < height / 2; y++) {
    for (let x = 0; x < width; x++) {
      for (let c = 0; c < numComponents; c++) {
        const i = (y * width + x) * numComponents + c
        const flippedI = ((height - y - 1) * width + x) * numComponents + c
        const tmp = data[i]
        data[i] = data[flippedI]
        data[flippedI] = tmp
      }
    }
  }
}
236951
def _invert(color, **kwargs):
    
    col = ColorValue(color)
    args = [
        255.0 - col.value[0],
        255.0 - col.value[1],
        255.0 - col.value[2],
        col.value[3],
    ]
    inverted = ColorValue(args)
    return inverted