text:
#ifndef _OTF_HEADERDECODER_H
#define _OTF_HEADERDECODER_H

#include <cstdint>
#include <memory>
#include <vector>
#include <string>
#include <algorithm>

#include "Token.h"

namespace sbe {
namespace otf {

class OtfHeaderDecoder
{
public:
    explicit OtfHeaderDecoder(const std::shared_ptr<std::vector<Token>>& tokens)
    {
        m_encodedLength = tokens->at(0).encodedLength();

        Token* blockLengthToken = nullptr;
        Token* templateIdToken = nullptr;
        Token* schemaIdToken = nullptr;
        Token* versionToken = nullptr;

        std::for_each(tokens->begin(), tokens->end(), [&](Token& token)
        {
            const std::string& name = token.name();

            if (name == "blockLength")
            {
                blockLengthToken = &token;
            }
            else if (name == "templateId")
            {
                templateIdToken = &token;
            }
            else if (name == "schemaId")
            {
                schemaIdToken = &token;
            }
            else if (name == "version")
            {
                versionToken = &token;
            }
        });

        if (nullptr == blockLengthToken)
        {
            throw std::runtime_error("blockLength token not found");
        }

        m_blockLengthOffset = blockLengthToken->offset();
        m_blockLengthType = blockLengthToken->encoding().primitiveType();
        m_blockLengthByteOrder = blockLengthToken->encoding().byteOrder();

        if (nullptr == templateIdToken)
        {
            throw std::runtime_error("templateId token not found");
        }

        m_templateIdOffset = templateIdToken->offset();
        m_templateIdType = templateIdToken->encoding().primitiveType();
        m_templateIdByteOrder = templateIdToken->encoding().byteOrder();

        if (nullptr == schemaIdToken)
        {
            throw std::runtime_error("schemaId token not found");
        }

        m_schemaIdOffset = schemaIdToken->offset();
        m_schemaIdType = schemaIdToken->encoding().primitiveType();
        m_schemaIdByteOrder = schemaIdToken->encoding().byteOrder();

        if (nullptr == versionToken)
        {
            throw std::runtime_error("version token not found");
        }

        m_schemaVersionOffset = versionToken->offset();
        m_schemaVersionType = versionToken->encoding().primitiveType();
        m_schemaVersionByteOrder = versionToken->encoding().byteOrder();
    }

    inline std::uint32_t encodedLength() const
    {
        return static_cast<std::uint32_t>(m_encodedLength);
    }

    /*
     * All elements must be unsigned integers according to Specification
     */

    std::uint64_t getTemplateId(const char *headerBuffer) const
    {
        return Encoding::getUInt(m_templateIdType, m_templateIdByteOrder, headerBuffer + m_templateIdOffset);
    }

    std::uint64_t getSchemaId(const char *headerBuffer) const
    {
        return Encoding::getUInt(m_schemaIdType, m_schemaIdByteOrder, headerBuffer + m_schemaIdOffset);
    }

    std::uint64_t getSchemaVersion(const char *headerBuffer) const
    {
        return Encoding::getUInt(m_schemaVersionType, m_schemaVersionByteOrder, headerBuffer + m_schemaVersionOffset);
    }

    std::uint64_t getBlockLength(const char *headerBuffer) const
    {
        return Encoding::getUInt(m_blockLengthType, m_blockLengthByteOrder, headerBuffer + m_blockLengthOffset);
    }

private:
    std::int32_t m_encodedLength;
    std::int32_t m_blockLengthOffset;
    std::int32_t m_templateIdOffset;
    std::int32_t m_schemaIdOffset;
    std::int32_t m_schemaVersionOffset;
    PrimitiveType m_blockLengthType;
    PrimitiveType m_templateIdType;
    PrimitiveType m_schemaIdType;
    PrimitiveType m_schemaVersionType;
    ByteOrder m_blockLengthByteOrder;
    ByteOrder m_templateIdByteOrder;
    ByteOrder m_schemaIdByteOrder;
    ByteOrder m_schemaVersionByteOrder;
};

}}

#endif


text:
<?php
namespace Thumbnailer\Thumbnailer;

use Thumbnailer\Thumbnailer\Exception\GDLibraryMissingException;
use Thumbnailer\Thumbnailer\Exception\NoSourceException;

/**
 * Resize an image
 *
 * @Version 1.0
 * @author Sergio Rinaudo
 */
class Thumbnailer
	implements ThumbnailerInterface
{
	/**
	 * Quality of the resized image
	 * @var int
	 */
	private $quality = 100;

	/**
	 * The opened (source) image
	 * @var string
	 */
	private $sourceImagePath;

	/**
	 * The informations extracted from the source image
	 * @var null|array
	 */
	private $imageInfo;

	/**
	 * Image extension
	 * @var string
	 */
	private $extension;

	/**
	 * Source Image resource
	 * @var resource
	 */
	private $sourceImageResource;

	/**
	 * Destination Image resource
	 * @var resource
	 */
	private $destImageResource;

	/**
	 * Destination image calculate width
	 * @var int
	 */
	private $destImageWidth;

	/**
	 * Destination image calculated height
	 * @var int
	 */
	private $destImageHeight;

	/**
     * Class construct.
     *
     * @throws GDLibraryMissingException
     */
    public function __construct()
    {
        if(!function_exists("gd_info")) {
            throw new GDLibraryMissingException();
        }
    }

    /**
     * (non-PHPdoc)
     * @see \Thumbnailer\Thumbnailer\ThumbnailerInterface::parseConfig()
     */
    public function parseConfig($config)
    {
    	if(isset($config['quality'])) {
			$this->setQuality($config['quality']);
    	}
    }

    /**
     * Set the quality value
     *
     * @return \Thumbnailer\Thumbnailer\Thumbnailer
     */
    public function setQuality($quality)
    {
    	$this->quality = $quality;
    }

    /**
     * Get the quality value
     *
     * @return int
     */
    public function getQuality()
    {
    	return $this->quality;
    }

    /**
     * Set extension value
     *
     * @return \Thumbnailer\Thumbnailer\Thumbnailer
     */
    public function setExtension($extension)
    {
    	$this->extension = strtolower($extension);
    }

    /**
     * Get extension value
     *
     * @return string
     */
    public function getExtension()
    {
    	return $this->extension;
    }

    /**
     * (non-PHPdoc)
     * @see \Thumbnailer\Thumbnailer\ThumbnailerInterface::open()
     */
    public function open($sourceImagePath)
    {
        if(!file_exists($sourceImagePath) || !is_readable($sourceImagePath)) {
            throw new \RuntimeException("File '" . $sourceImagePath . "' does *not* exists OR is *not* readable.");
        }
    	$this->sourceImagePath = $sourceImagePath;
    	$this->parseImageInfo()
    		->initSourceImageResource();

    	return $this;
    }

    /**
     * (non-PHPdoc)
     * @see \Thumbnailer\Thumbnailer\ThumbnailerInterface::parseImageInfo()
     */
    public function parseImageInfo()
    {
    	if (null === $this->sourceImagePath) {
    		throw new NoSourceException();
    	}

    	$pathinfo = pathinfo($this->sourceImagePath);
    	if (!is_array($pathinfo)) {
    		throw new \RuntimeException("It is not possible to correctly get pathinfo for the image file '" . $this->sourceImagePath . "' ");
    	}

        $imagesize = getimagesize($this->sourceImagePath);
        if (!is_array($imagesize)) {
            throw new \RuntimeException("It is not possible to correctly get imagesize for the image file '" . $this->sourceImagePath . "' ");
        }

    	$info = $pathinfo + $imagesize;

        if (isset($info[0])) {
            $info['width'] = $info[0];
        } else {
            throw new \RuntimeException("Unable to get width for the image file '" . $this->sourceImagePath . "' ");
        }

        if (isset($info[1])) {
            $info['height'] = $info[1];
        } else {
            throw new \RuntimeException("Unable to get height for the image file '" . $this->sourceImagePath . "' ");
        }

        if (!isset($info['mime'])) {
            throw new \RuntimeException("Unable to get mimetype for the image file '" . $this->sourceImagePath . "' ");
        }

        unset($info[0], $info[1], $info[2], $info[3]);

        switch(strtolower($info['mime'])) {
		case 'image/png':
			$info['extension'] = 'png';
            break;

		case 'image/jpeg':
			$info['extension'] = 'jpg';
            break;

		case 'image/gif':
			$info['extension'] = 'gif';
            break;

		default:
			throw new \RuntimeException("Unable to get extension for the image file '" . $this->sourceImagePath . "' ");
            break;
        }

        // We set the default width/height values for the destination image if resize is not called
        $this->destImageWidth = $info['width'];
        $this->destImageHeight = $info['height'];

        $this->setExtension($info['extension']);
        $this->imageInfo = $info;

    	return $this;
    }

    /**
     * Get the source image info
     *
     * @return array
     */
    public function getImageInfo()
    {
    	return $this->imageInfo;
    }

    /**
     * Get the source resource image
     *
     * @throws \RuntimeException
     * @return resource
     */
    public function getSourceImageResource()
    {
		return $this->sourceImageResource;
    }

    /**
     * Init the source image resource
     *
     * @throws \RuntimeException
     * @return \Thumbnailer\Thumbnailer\Thumbnailer
     */
    protected function initSourceImageResource()
    {
    	$ext = $this->getExtension();

    	switch($ext) {
		case 'gif':
			$this->sourceImageResource = ImageCreateFromGif($this->sourceImagePath);
			break;

		case 'jpg':
			$this->sourceImageResource = ImageCreateFromJpeg($this->sourceImagePath);
			break;

		case 'png':
			$this->sourceImageResource = ImageCreateFromPng($this->sourceImagePath);
			break;

		default:
			throw new \RuntimeException("An error occurred trying to create the image, extension '" . $ext. "' is not supported");
			break;
    	}

    	return $this;
    }

    /**
     * Init the destination resource image.
     * This is an empty image and use the width and height values
     * of the source image if resize is not called by the user
     *
     * @throws \RuntimeException
     * @return resource
     */
    protected function initDestImageResource()
    {
    	// gif does not supports truecolor for resize
    	if (function_exists("ImageCreateTrueColor") && $this->getExtension() != 'gif') {
    		$this->destImageResource = ImageCreateTrueColor($this->destImageWidth, $this->destImageHeight);
    	} else {
    		$this->destImageResource = ImageCreate($this->destImageWidth, $this->destImageHeight);
    	}

    	return $this;
    }

    /**
     * (non-PHPdoc)
     * @see \Thumbnailer\Thumbnailer\ThumbnailerInterface::resize()
     */
    public function resize($width = 0, $height = 0)
    {
        if ($width != 0 || $height != 0) {
            $width = $this->getNewWidth($width, $height);
            $height = $this->getNewHeight($width, $height);
        } else {
            $width = $this->imageInfo['width'];
            $height = $this->imageInfo['height'];
        }

        $this->destImageWidth = $width;
        $this->destImageHeight = $height;

        return $this;
    }

    /**
     * (non-PHPdoc)
     * @see \Thumbnailer\Thumbnailer\ThumbnailerInterface::render()
     */
    public function render($destImagePath = null)
    {
    	$this->initDestImageResource();
    	$this->applyTransparency();

    	ImageCopyResampled(
	    	$this->destImageResource,
	    	$this->sourceImageResource,
	    	0, 0, 0, 0,
	    	$this->destImageWidth,
	    	$this->destImageHeight,
	    	$this->imageInfo['width'],
	    	$this->imageInfo['height']
    	);

        // Let's try to delete the image if already exists
        if(null !== $destImagePath) {
            if (is_file($destImagePath) && file_exists($destImagePath)) {
                if (!unlink($destImagePath)) {
                    throw new \RuntimeException("File '" . $destImagePath . "' already exists and it is *not* writeable");
                }
            }
        } else {
            header('Content-type: ' . $this->imageInfo['mime']);
        }

		switch($this->getExtension()) {
		case 'gif':
			return ImageGif($this->destImageResource, $destImagePath);
			break;

		case 'jpg':
			return ImageJpeg($this->destImageResource, $destImagePath, $this->getQuality());
            break;

		case 'png':
			return ImagePng($this->destImageResource, $destImagePath);
            break;
        }

        return false;
    }

    /**
     * (non-PHPdoc)
     * @see \Thumbnailer\Thumbnailer\ThumbnailerInterface::save()
     */
    public function save($destImagePath)
    {
    	return $this->render($destImagePath);
    }

    /**
     * Returns the new $width value
     *
     * @param int $width
     * @param int $height
     * @return int
     */
    protected function getNewWidth($width, $height)
    {
        if ($width > 0) {
            return $width;
        }

        // original height : new height = original width : X
        return $height * $this->imageInfo['width'] / $this->imageInfo['height'];
    }

    /**
     * Returns the new $height value
     *
     * @param int $width
     * @param int $height
     * @return int
     */
    protected function getNewHeight($width, $height)
    {
        if ($height > 0) {
            return $height;
        }

        // original width : new width = original height : X
        return $width * $this->imageInfo['height'] / $this->imageInfo['width'];
    }

    /**
     * This is needed to keep trasparency, for more information visit
     * http://www.php.net/manual/en/function.imagecolortransparent.php
     *
     * @return \Thumbnailer\Thumbnailer\Thumbnailer
     */
    protected function applyTransparency()
    {
        $transparencyIndex = imagecolortransparent($this->sourceImageResource);
        $transparencyColor = array('red' => 255, 'green' => 255, 'blue' => 255);

        if ($transparencyIndex >= 0) {
            $transparencyColor = imagecolorsforindex($this->sourceImageResource, $transparencyIndex);
        }

        $transparencyIndex = imagecolorallocate($this->destImageResource,
        		$transparencyColor['red'], $transparencyColor['green'], $transparencyColor['blue']);
        imagefill($this->destImageResource, 0, 0, $transparencyIndex);
        imagecolortransparent($this->destImageResource, $transparencyIndex);

        return $this;
    }
}

redpajama_set_name: RedPajamaGithub


text:
// Licensed to Cloudera, Inc. under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  Cloudera, Inc. licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.cloudera.api.model;

import java.util.List;

import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * A batch response, comprised of one or more response elements.
 */
@XmlRootElement(name = "batchResponse")
public class ApiBatchResponse extends ApiListBase<ApiBatchResponseElement> {
  private Boolean success;

  public ApiBatchResponse() {

  }

  public ApiBatchResponse(List<ApiBatchResponseElement> elements) {
    super(elements);
  }

  @XmlElementWrapper(name = ApiListBase.ITEMS_ATTR)
  public List<ApiBatchResponseElement> getElements() {
    return values;
  }

  public void setElements(List<ApiBatchResponseElement> elements) {
    this.values = elements;
  }

  /**
   * Read-only. True if every response element's
   * {@link ApiBatchResponseElement#getStatusCode()} is in the range [200, 300),
   * false otherwise.
   */
  public Boolean getSuccess() {
    return success;
  }

  public void setSuccess(Boolean success) {
    this.success = success;
  }
}


text:
/*-*- Mode: C++ -*-*/

#ifndef _BOX_H
#define _BOX_H
/************************************************************************
*
*
*************************************************************************
*
*  Ramani Pichumani
*  Spectroscopy Imaging Systems Corporation
*  Fremont, CA  94538
*
*************************************************************************/

#include <iostream>
#include <fstream>

using namespace std;

#include "msgprt.h"

// Its basetool "pnt" consists of 2 points, where pnt[0] defines
// upper-left corner of a box and pnt[1] defines bottom-right corner of
// a box
class Box : public Roitool
{
  protected:
    Fpoint ul_corner_on_data;	// Upper-left corner in data space.
    Fpoint lr_corner_on_data;

  private:
    // Used to implement "iterator" function.
    float *data;
    float *beg_of_row;
    float *end_of_row;
    int data_width;
    int roi_width;
    int roi_height;
    int row;

  public:
    Box(void);
    Box(float, float, float, float, Gframe *);
    ~Box(void);	// Currently not used by ROI Box

    // Used after ROI creation/mod
    void update_data_coords();

    // Used after rotating/reflecting image
    virtual void rot90_data_coords(int datawidth);
    virtual void flip_data_coords(int datawidth);

    // Used after window move/resize/zoom
    void update_screen_coords();

    // Note that x,y is current position of the cursor
    char *name(void) { return "box"; }
    virtual ReactionType create(short x, short y, short action = NULL);
    ReactionType create_done(short x, short y, short action = NULL);
    ReactionType resize(short x, short y) {
	create(x, y);
	return REACTION_NONE;
    }
    ReactionType resize_done(short x, short y) {
	create_done(x, y);
	return REACTION_NONE;
    }
    ReactionType move(short x, short y);
    virtual ReactionType move_done(short x, short y);
    virtual Roitool *copy(Gframe *);
    virtual void draw(void);
    virtual void mark(void);
    virtual void redimension(short width, short height);
    virtual Roitool* recreate() { return new Box; }
    // Select a box (move or resize)
    virtual Flag is_selected(short x, short y);
    void save(ofstream &);
    void load(ifstream &);

    int area(void);			// Return area of a box

    float *FirstPixel();
    float *NextPixel();
    Fpoint ul_corner_data() { return ul_corner_on_data; }
    Fpoint lr_corner_data() { return lr_corner_on_data; }
};

class Selector : public Box {
  public:
    Selector()  :  Box() { created_type = ROI_SELECTOR; }
#ifndef LINUX
    ~Selector() { Box::~Box(); }
#endif
    virtual Roitool* recreate() { return this; }
    void histostats(int *, int, double *, double *,
		    double *, double *, double *, double *){
	msgerr_print("Selector::histostats: Please select an ROI first");
    }
};

#endif


text:
title=Registration
date=2018-11-10
type=page
status=published
~~~~~~

Registration will be available soon! :)
<br/>


text:
@interface ConversationTableManager ()<Y2WUserConversationsDelegate>

@property (nonatomic, weak) Y2WUserConversations *userConversations;

@property (nonatomic, retain) NSMutableArray *reloadDatas;

@end

@implementation ConversationTableManager {
    NSMutableArray *newConversationDatas;
}

- (void)dealloc {
    [self.userConversations removeDelegate:self];
}

- (instancetype)init {
    if (self = [super init]) {
        self.conversationDatas = [NSMutableArray array];
        self.reloadDatas = [NSMutableArray array];

        [self.userConversations addDelegate:self];
    }
    return self;
}

#pragma mark - ———— Y2WUserConversationsDelegate ———— -

- (void)userConversationsWillChangeContent:(Y2WUserConversations *)userConversations {
    [self.reloadDatas removeAllObjects];

    newConversationDatas = [self.conversationDatas mutableCopy];
}

- (void)userConversations:(Y2WUserConversations *)userConversations onAddUserConversation:(Y2WUserConversation *)userConversation {

    for (Y2WUserConversation *conversation in newConversationDatas) {
        if ([conversation isEqual:userConversation]) {
            return;
        }
    }
    [newConversationDatas addObject:userConversation];
}

- (void)userConversations:(Y2WUserConversations *)userConversations onDeleteUserConversation:(Y2WUserConversation *)userConversation {

    for (Y2WUserConversation *conversation in newConversationDatas) {
        if ([conversation isEqual:userConversation]) {

            [newConversationDatas removeObject:conversation];
            return;
        }
    }
}

- (void)userConversations:(Y2WUserConversations *)userConversations onUpdateUserConversation:(Y2WUserConversation *)userConversation {
    for (Y2WUserConversation *conversation in newConversationDatas) {
        if ([conversation isEqual:userConversation]) {

            [self.reloadDatas addObject:userConversation];
            return;
        }
    }
}

- (void)userConversationsDidChangeContent:(Y2WUserConversations *)userConversations {

    // 排序
    [newConversationDatas sortUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"top" ascending:NO],
                                                 [NSSortDescriptor sortDescriptorWithKey:@"updatedAt" ascending:NO]]];

    NSMutableArray *insertIndexPaths = [[self getInsertIndexPaths] mutableCopy];
    NSMutableArray *deleteIndexPaths = [[self getDeleteIndexPaths] mutableCopy];
    NSArray *reloadIndexPaths = [self getReloadIndexPaths];

    NSMutableDictionary *oldIndexPaths = [NSMutableDictionary dictionary];
    [self.conversationDatas enumerateObjectsUsingBlock:^(Y2WUserConversation *conversation, NSUInteger idx, BOOL * _Nonnull stop) {
        oldIndexPaths[conversation.userConversationId] = [NSIndexPath indexPathForRow:idx inSection:0];
    }];

    NSMutableDictionary *newIndexPaths = [NSMutableDictionary dictionary];
    [newConversationDatas enumerateObjectsUsingBlock:^(Y2WUserConversation *conversation, NSUInteger idx, BOOL * _Nonnull stop) {
        NSIndexPath *oldIndexPath = oldIndexPaths[conversation.userConversationId];
        NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:idx inSection:0];

        if (oldIndexPath) {
            if (![oldIndexPath isEqual:newIndexPath]) {
                [insertIndexPaths addObject:newIndexPath];
                [deleteIndexPaths addObject:oldIndexPath];
//                if ([oldIndexPath compare:newIndexPath] == NSOrderedDescending) {
//                    newIndexPaths[conversation.userConversationId] = newIndexPath;
//                    NSLog(@"\n-%@-\n%@\n%@",conversation.name,oldIndexPath,newIndexPath);
//                }
            }
        }
    }];

    self.conversationDatas = newConversationDatas;
    newConversationDatas = nil;

    dispatch_async(dispatch_get_main_queue(), ^{

//        if ([self.delegate respondsToSelector:@selector(tableViewIndexPathWillChangeContent:)]) {
//            [self.delegate tableViewIndexPathWillChangeContent:self];
//        }
//
//        for (NSIndexPath *indexPath in insertIndexPaths) {
//            if ([self.delegate respondsToSelector:@selector(tableViewIndexPathManager:atIndexPath:newIndexPath:forChangeType:)]) {
//                [self.delegate tableViewIndexPathManager:self atIndexPath:nil newIndexPath:indexPath forChangeType:TableViewIndexPathChangeInsert];
//            }
//        }
//
//        for (NSIndexPath *indexPath in deleteIndexPaths) {
//            if ([self.delegate respondsToSelector:@selector(tableViewIndexPathManager:atIndexPath:newIndexPath:forChangeType:)]) {
//                [self.delegate tableViewIndexPathManager:self atIndexPath:indexPath newIndexPath:nil forChangeType:TableViewIndexPathChangeDelete];
//            }
//        }

//        for (id obj in newConversationDatas) {
//            NSIndexPath *oldIndexPath = oldIndexPaths[obj];
//            NSIndexPath *newIndexPath = newIndexPaths[obj];
//            if (newIndexPath) {
//                if ([self.delegate respondsToSelector:@selector(tableViewIndexPathManager:atIndexPath:newIndexPath:forChangeType:)]) {
//                    [self.delegate tableViewIndexPathManager:self atIndexPath:oldIndexPath newIndexPath:newIndexPath forChangeType:TableViewIndexPathChangeMove];
//                }
//            }
//        }

//        for (NSIndexPath *indexPath in reloadIndexPaths) {
//            if ([self.delegate respondsToSelector:@selector(tableViewIndexPathManager:atIndexPath:newIndexPath:forChangeType:)]) {
//                [self.delegate tableViewIndexPathManager:self atIndexPath:indexPath newIndexPath:nil forChangeType:TableViewIndexPathChangeUpdate];
//            }
//        }
//
//        if ([self.delegate respondsToSelector:@selector(tableViewIndexPathDidChangeContent:)]) {
//            [self.delegate tableViewIndexPathDidChangeContent:self];
//        }

        [self change:^{
            for (NSIndexPath *indexPath in insertIndexPaths) {
                if ([self.delegate respondsToSelector:@selector(tableViewIndexPathManager:atIndexPath:newIndexPath:forChangeType:)]) {
                    [self.delegate tableViewIndexPathManager:self atIndexPath:nil newIndexPath:indexPath forChangeType:TableViewIndexPathChangeInsert];
                }
            }

            for (NSIndexPath *indexPath in deleteIndexPaths) {
                if ([self.delegate respondsToSelector:@selector(tableViewIndexPathManager:atIndexPath:newIndexPath:forChangeType:)]) {
                    [self.delegate tableViewIndexPathManager:self atIndexPath:indexPath newIndexPath:nil forChangeType:TableViewIndexPathChangeDelete];
                }
            }
        }];

        [self change:^{
            for (NSIndexPath *indexPath in reloadIndexPaths) {
                if ([self.delegate respondsToSelector:@selector(tableViewIndexPathManager:atIndexPath:newIndexPath:forChangeType:)]) {
                    [self.delegate tableViewIndexPathManager:self atIndexPath:indexPath newIndexPath:nil forChangeType:TableViewIndexPathChangeUpdate];
                }
            }
        }];
    });
}

- (void)change:(void(^)(void))block {

    if ([self.delegate respondsToSelector:@selector(tableViewIndexPathWillChangeContent:)]) {
        [self.delegate tableViewIndexPathWillChangeContent:self];
    }

    block();

    if ([self.delegate respondsToSelector:@selector(tableViewIndexPathDidChangeContent:)]) {
        [self.delegate tableViewIndexPathDidChangeContent:self];
    }
}

#pragma mark - ———— Helper ———— -

- (NSArray *)getInsertIndexPaths {

    return [[newConversationDatas qs_mapObjectsUsingBlock:^id(id obj, NSUInteger index) {
        if ([self.conversationDatas indexOfObject:obj] == NSNotFound) {
            return [NSIndexPath indexPathForRow:index inSection:0];
        };
        return [NSNull null];
    }] qs_compact];
}

- (NSArray *)getDeleteIndexPaths {

    return [[self.conversationDatas qs_mapObjectsUsingBlock:^id(id obj, NSUInteger index) {
        if ([newConversationDatas indexOfObject:obj] == NSNotFound) {
            return [NSIndexPath indexPathForRow:index inSection:0];
        };
        return [NSNull null];
    }] qs_compact];
}

- (NSArray *)getReloadIndexPaths {

    return [[self.reloadDatas qs_mapObjectsUsingBlock:^id(id obj, NSUInteger index) {
        if ([newConversationDatas indexOfObject:obj] != NSNotFound) {
            return [NSIndexPath indexPathForRow:index inSection:0];
        };
        return [NSNull null];
    }] qs_compact];
}

#pragma mark - ———— getter ———— -

- (Y2WUserConversations *)userConversations {

    if (!_userConversations) {
        _userConversations = [Y2WUsers getInstance].getCurrentUser.userConversations;
    }
    return _userConversations;
}

@end


text:
//
//  ViewController.m
//  ANLock Demo
//
//  Created by SpringOx on 12/21/15.
//  Copyright © 2015 SpringOx. All rights reserved.
//

#import "ViewController.h"
#import <pthread.h>
#import <libkern/OSAtomic.h>
#import "ANReadWriteLock.h"
#import "ANRecursiveRWLock.h"

@interface ViewController ()
{
    dispatch_semaphore_t _semaphore;
    ANRecursiveRWLock *_rwLock;
    pthread_mutex_t _mutex;
    int _readWriteFlag;
}

@property (atomic, assign) NSUInteger atomicFlag;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)didPressTestButtonAction:(id)sender
{
    UIButton *btn = (UIButton *)sender;
    switch (btn.tag) {
        case 0:
            [self testLockList];
            break;
        case 1:
            [self test_dispatch_semaphore];
            break;
        case 2:
            [self testOSSpinLock];
            break;
        case 3:
            [self testReadWriteLock];
            break;
        case 4:
            [self testRecursiveRWLock];
            break;
        case 5:
            [self testRWReadPerformance];
            break;
        case 6:
            [self testMutexReadPerformance];
            break;

        default:
            break;
    }
}

#pragma mark -

- (void)testLockList
{
    CFTimeInterval timeBefore;
    CFTimeInterval timeCurrent;
    NSUInteger i;
    //一千万次的锁操作执行
    NSUInteger count = 1000*10000;

    //@synchronized
    id obj = [[NSObject alloc]init];;
    timeBefore = CFAbsoluteTimeGetCurrent();
    for(i=0; i<count; i++){
        @synchronized(obj){
        }
    }
    timeCurrent = CFAbsoluteTimeGetCurrent();
    printf("@synchronized used : %f\n", timeCurrent-timeBefore);

    //NSLock
    NSLock *lock = [[NSLock alloc]init];
    timeBefore = CFAbsoluteTimeGetCurrent();
    for(i=0; i<count; i++){
        [lock lock];
        [lock unlock];
    }
    timeCurrent = CFAbsoluteTimeGetCurrent();
    printf("NSLock used : %f\n", timeCurrent-timeBefore);

    //NSRecursiveLock
    NSRecursiveLock *recursiveLock = [[NSRecursiveLock alloc]init];
    timeBefore = CFAbsoluteTimeGetCurrent();
    for(i=0; i<count; i++){
        [recursiveLock lock];
        [recursiveLock unlock];
    }
    timeCurrent = CFAbsoluteTimeGetCurrent();
    printf("NSRecursiveLock used : %f\n", timeCurrent-timeBefore);

    //NSCondition
    NSCondition *condition = [[NSCondition alloc]init];
    timeBefore = CFAbsoluteTimeGetCurrent();
    for(i=0; i<count; i++){
        [condition lock];
        [condition unlock];
    }
    timeCurrent = CFAbsoluteTimeGetCurrent();
    printf("NSCondition used : %f\n", timeCurrent-timeBefore);

    //NSConditionLock
    NSConditionLock *conditionLock = [[NSConditionLock alloc]init];
    timeBefore = CFAbsoluteTimeGetCurrent();
    for(i=0; i<count; i++){
        [conditionLock lock];
        [conditionLock unlock];
    }
    timeCurrent = CFAbsoluteTimeGetCurrent();
    printf("NSConditionLock used : %f\n", timeCurrent-timeBefore);

    //ANReadWriteLock write
    ANReadWriteLock *wLock = [[ANReadWriteLock alloc]init];
    timeBefore = CFAbsoluteTimeGetCurrent();
    for(i=0; i<count; i++){
        [wLock writeLock];
        [wLock writeUnlock];
    }
    timeCurrent = CFAbsoluteTimeGetCurrent();
    printf("ANReadWriteLock write used : %f\n", timeCurrent-timeBefore);

    //ANReadWriteLock read
    ANReadWriteLock *rLock = [[ANReadWriteLock alloc]init];
    timeBefore = CFAbsoluteTimeGetCurrent();
    for(i=0; i<count; i++){
        [rLock readLock];
        [rLock readUnlock];
    }
    timeCurrent = CFAbsoluteTimeGetCurrent();
    printf("ANReadWriteLock read used : %f\n", timeCurrent-timeBefore);

    //pthread_mutex
    pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
    /*
     pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
     pthread_mutexattr_t attr;
     pthread_mutexattr_init(&attr);
     //设置锁的属性为可递归
     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
     pthread_mutex_init(&mutex, &attr);
     pthread_mutexattr_destroy(&attr);
     */
    timeBefore = CFAbsoluteTimeGetCurrent();
    for(i=0; i<count; i++){
        pthread_mutex_lock(&mutex);
        pthread_mutex_unlock(&mutex);
    }
    timeCurrent = CFAbsoluteTimeGetCurrent();
    printf("pthread_mutex used : %f\n", timeCurrent-timeBefore);

    //dispatch_semaphore
    dispatch_semaphore_t semaphore = dispatch_semaphore_create(1);
    timeBefore = CFAbsoluteTimeGetCurrent();
    for(i=0; i<count; i++){
        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
        dispatch_semaphore_signal(semaphore);
    }
    timeCurrent = CFAbsoluteTimeGetCurrent();
    printf("dispatch_semaphore used : %f\n", timeCurrent-timeBefore);

    //OSSpinLockLock
    OSSpinLock spinlock = OS_SPINLOCK_INIT;
    timeBefore = CFAbsoluteTimeGetCurrent();
    for(i=0; i<count; i++){
        OSSpinLockLock(&spinlock);
        OSSpinLockUnlock(&spinlock);
    }
    timeCurrent = CFAbsoluteTimeGetCurrent();
    printf("OSSpinLock used : %f\n", timeCurrent-timeBefore);

    //Atomic Flag
    timeBefore = CFAbsoluteTimeGetCurrent();
    for(i=0; i<count; i++){
        self.atomicFlag = count;
    }
    timeCurrent = CFAbsoluteTimeGetCurrent();
    printf("Atomic Set/Get used : %f\n", timeCurrent-timeBefore);
}

#pragma mark -

- (void)test_dispatch_semaphore
{
    //主线程中
    _semaphore = dispatch_semaphore_create(1);

    //线程1
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        dispatch_semaphore_wait(_semaphore, DISPATCH_TIME_FOREVER);
        [self threadMethod1];
        sleep(3);
        dispatch_semaphore_signal(_semaphore);
    });

    //线程2
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        sleep(1);
        dispatch_semaphore_wait(_semaphore, DISPATCH_TIME_FOREVER);
        [self threadMethod2];
        dispatch_semaphore_signal(_semaphore);
    });
}

- (void)testOSSpinLock
{
    //主线程中
    __block OSSpinLock spinlock = OS_SPINLOCK_INIT;

    //线程1
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        OSSpinLockLock(&spinlock);
        [self threadMethod1];
        sleep(3);
        OSSpinLockUnlock(&spinlock);
    });

    for (int i=0; i<10; i++) {
        //线程2
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            sleep(1);
            OSSpinLockLock(&spinlock);
            [self threadMethod2];
            OSSpinLockUnlock(&spinlock);
        });
    }
}

- (void)threadMethod1
{
    // 测试可重入性
    /*
     dispatch_semaphore_wait(_semaphore, DISPATCH_TIME_FOREVER);
     NSLog(@"%@",NSStringFromSelector(_cmd));
     dispatch_semaphore_signal(_semaphore);
     */
    NSLog(@"%@",NSStringFromSelector(_cmd));
}

- (void)threadMethod2
{
    NSLog(@"%@",NSStringFromSelector(_cmd));
}

#pragma mark -

- (void)testReadWriteLock
{
    ANReadWriteLock *rwLock = [[ANReadWriteLock alloc] init];

    //线程Write
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [rwLock writeLock];
        [self writeMethod];
        sleep(3);
        [rwLock writeUnlock];
    });

    for (int i=0; i<3; i++) {
        for (int j=0; j<5; j++) {
            //线程Read
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                sleep(1);
                [rwLock readLock];
                [self readMethod];
                [rwLock readUnlock];
            });
        }

        //线程Write
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            sleep(1);
            [rwLock writeLock];
            [self writeMethod];
            [rwLock writeUnlock];
        });
    }
}

- (void)testRecursiveRWLock
{
    ANRecursiveRWLock *rwLock = [[ANRecursiveRWLock alloc] init];

    //线程Write
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [rwLock writeLock];
        [self writeMethod];
        sleep(3);
        [rwLock writeUnlock];
    });

    for (int i=0; i<3; i++) {
        for (int j=0; j<5; j++) {
            //线程Read
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                sleep(1);
                [rwLock readLock];
                [self readMethod];
                [rwLock readUnlock];
            });
        }

        //线程Write
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            sleep(1);
            [rwLock writeLock];
            [self writeMethod];
            [rwLock writeUnlock];
        });
    }
}

- (int)readMethod
{
    NSLog(@"%@ flag %d",NSStringFromSelector(_cmd), _readWriteFlag);
    return _readWriteFlag;
}

- (void)writeMethod
{
    ++_readWriteFlag;
    NSLog(@"%@ flag %d",NSStringFromSelector(_cmd), _readWriteFlag);
}

#pragma mark -

- (void)testRWReadPerformance
{
    _rwLock = [[ANRecursiveRWLock alloc] init];

    int count = 1000;
    for (int i=0; i<count; i++) {
        [NSThread detachNewThreadSelector:@selector(rwReadTest)
                                 toTarget:self
                               withObject:nil];
    }
}

- (void)rwReadTest
{
    [_rwLock readLock];
    usleep(100);
    NSLog(@"%@ flag %d",NSStringFromSelector(_cmd), _readWriteFlag);
    [_rwLock readUnlock];
}

- (void)testMutexReadPerformance
{
     pthread_mutexattr_t attr;
     pthread_mutexattr_init(&attr);
     //设置锁的属性为可递归
     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
     pthread_mutex_init(&_mutex, &attr);
     pthread_mutexattr_destroy(&attr);

    int count = 1000;
    for (int i=0; i<count; i++) {
        [NSThread detachNewThreadSelector:@selector(mutexReadTest)
                                 toTarget:self
                               withObject:nil];
    }
}

- (void)mutexReadTest
{
    pthread_mutex_lock(&_mutex);
    usleep(100);
    NSLog(@"%@ flag %d",NSStringFromSelector(_cmd), _readWriteFlag);
    pthread_mutex_unlock(&_mutex);
}

@end


text:
#pragma once

#include "core/math/types.h"
#include "resource/types.h"
#include "world/types.h"

namespace crown
{
/// Material
///
/// @ingroup World
struct Material
{
	const MaterialResource* _resource;
	char* _data;

	///
	void bind(ResourceManager& rm, ShaderManager& sm, u8 view, s32 depth = 0) const;

	/// Sets the @a value of the variable @a name.
	void set_float(StringId32 name, f32 value);

	/// Sets the @a value of the variable @a name.
	void set_vector2(StringId32 name, const Vector2& value);

	/// Sets the @a value of the variable @a name.
	void set_vector3(StringId32 name, const Vector3& value);

	/// Sets the @a value of the variable @a name.
	void set_vector4(StringId32 name, const Vector4& value);

	/// Sets the @a value of the variable @a name.
	void set_matrix4x4(StringId32 name, const Matrix4x4& value);
};

} // namespace crown