text:
layout: post
title: Auto
---

`auto` is a tool to [simplify code notation](http://www.stroustrup.com/C++11FAQ.html#auto). It has quickly become a firm favourite in my C++ arsenal, helping me to write type safe code that's easy to read and maintain. It can, and should, be used (almost) everywhere.

<!--more-->

> This article is my review of `auto`, drawn from personal experience and the work of others. I've tried to accredit the work of other authors in-line, and I've added an appendix of resources. I've condensed everything I've learned in to one place, and I will update this document as and when I discover new things. Please contact me with any comments or corrections using the buttons in the site footer.

* TOC
{:toc}

## Types

It's easy to assume that using `auto` can lead you to ignore type. I'd argue that it allows you to favour interface over type when you want to, and still allows you to be explicit.

### Deduction

If you have written a template then you have ignored explicit type: you've abstracted the implementation details away to just an interface. Abstraction is a key technique for any programmer, and `auto` is just another tool to help you use it. `auto` type deduction is just the [template type deduction](http://en.cppreference.com/w/cpp/language/template_argument_deduction) mechanism by another name, here's a summary of the rules:

#### Base types

For base types `auto` works as expected:

{% highlight cpp %}
auto a = Adam(); // type Adam, deduced from constructor
auto b = a;	// type Adam, deduced from constructor
{% endhighlight %}

#### `const`

High-level `const` is not preserved:

{% highlight cpp %}
const auto a = 5; // const int
auto b = a; // int
{% endhighlight %}

`a` is a `const int`, `b` is an `int`. `b` is an independent variable, and has it's own `const` state.

#### `Type&`

References behave in a similar fashion:

{% highlight cpp %}
auto a = 5; // int
auto& b = a; // int&
auto c = b; // int
{% endhighlight %}

`c` is an `int` and not an `int&`, again, only the basic type is preserved. This means that `c` is a copy of `a`.

*Note: the default `auto` behaviour is copy*

#### `Type*`

Pointers behave differently, as the `*` modifies the base type:

{% highlight cpp %}
auto a = 5;	// int
auto b = &a; // int*
auto c = b;	// int*
auto d = &c; // int**
{% endhighlight %}

#### `const *`

`const *` behaves the same as `*`, again modifying the base type:

{% highlight cpp %}
const auto a = 5;	// int
auto b = &a;		// int* const
auto c = b;			// int* const
{% endhighlight %}

Take care with `const`:

{% highlight cpp %}
auto a = 5; 		// int
const auto b = &a;	// const int*
auto c = b;			// int*
{% endhighlight %}

#### `const * const`

{% highlight cpp %}
const auto a = 5;	// int
const auto b = &a;	// const int * const
{% endhighlight %}

#### Gotcha - Functions returning references

This subtlety tripped me up when I was first getting to grips with `auto`. You get in to the pattern of jumping to definition to find a function's return type, so you would expect (well you may not, if you've paid attention to the previous sections, but I did!) that the type deduced by `auto` would match the type returned by the function.

Consider a using `auto` to store a pointer to a member variable returned by an accessor function:

{% highlight cpp %}
Obj* GetPointer() { return &m_Obj; }
auto ptr = GetPointer(); // ptr is of type Obj*
{% endhighlight %}

Now apply that logic to a function that return a member reference:

{% highlight cpp %}
Obj& GetReference() { return m_Obj; }
auto ref = GetReference();
{% endhighlight %}

What is ref's type? It's an `Obj`, not an `Obj&`.

### Explicit types

If you need to use an explicit type [use constructors](http://herbsutter.com/2013/06/13/gotw-93-solution-auto-variables-part-2/) or casts:

{% highlight cpp %}
auto var = my_type(obj);
auto var = static_cast<my_type>(obj);
auto var = dynamic_cast<my_type*>(obj);
{% endhighlight %}

### Closures

One of the coolest things about `auto` is that it unlocks types only known to the compiler. Lambdas are an example of this mechanism: their type is generated at compile time. Without `auto` type deduction we wouldn't be able store the temporary function as a variable.

{% highlight cpp %}
auto lambda = [](){ ... };
lambda();
{% endhighlight %}

### `auto` return types

Suffix return type syntax is used in lambdas to remove the need to manually specify return type:

{% highlight cpp %}
[]()->bool{ return true; };
[](){ return true; };
{% endhighlight %}

### Generic lambdas

C++14 will bring a pretty cool new addition to lambdas: generic arguments.

{% highlight cpp %}
[](auto& obj){ ... }
{% endhighlight %}

At first I thought this mechanism was added so that you don't need to remember the exact container value types (see earlier point on Containers), but I've since realised it's true power comes from being used in a polymorphic context:

{% highlight cpp %}
std::vector<Car> cars;
std::vector<Bus> buses;

auto lambda = [](auto& obj){ ... };

for (auto& car : cars)
	lambda(car);

for (auto& bus : buses)
	lambda(bus);
{% endhighlight %}

This is an example of [hiding type for compile time polymorphism](http://herbsutter.com/2013/08/12/gotw-94-solution-aaa-style-almost-always-auto/).

### Containers

A perfect example of `auto` making life easier is map iteration:

{% highlight cpp %}
std::map<std::string, MyType> map;

for (std::pair<std::string, MyType>& pair : map)
{
	...
}
{% endhighlight %}

The boilerplate heavy code becomes:

{% highlight cpp %}
for (auto& pair : map)
{
	...
}
{% endhighlight %}

And in C++14:

{% highlight cpp %}
for (pair : map)
{
	...
}
{% endhighlight %}

### To `const` or not to `const`

Credit for the previous example goes to Scott Meyers *[Effective Modern C++](http://shop.oreilly.com/product/0636920033707.do), Item 5: Prefer `auto` to explicit type declarations*. He points out that not only does it make it easier to read, there's actually an error in the original form, though you'd be hard pressed to find it: key types in unordered_map are `const`, so the pair type declaration should be `std::pair<const std::string, MyType>`.

`const` correctness is important. It ensures thread safety and gives the compiler greater freedom to optimise. When iterating a container should you use a `const` or a mutable iterator? `auto` will deduce the right type from context, and not only is it correct *now*, it will *always* be correct, even after you refactor your algorithm to modify internal state.

### Gotcha - Braced initialisers

Braced initialisation is uses a `std::initializer_list<>` mechanism to invoke a templated constructor. You'll see it used in the latest slides from

{% highlight cpp %}
Object obj{3};
Object obj{3, "bob"};
auto obj = Object{3, "bob"};
auto obj = {3};
std::vector<int> vector = {7, 4, 84, 81, 92, 2};
{% endhighlight %}

The coolest use I have found for braced initialisation is the [nlohmann/json
](https://github.com/nlohmann/json/blob/master/README.md) library. It uses nested `initializer_list`s to create objects in code using a syntax that mimics the appearance of a json file:

{% highlight cpp %}
json j2 = {
  {"pi", 3.141},
  {"object", {
    {"currency", "USD"},
    {"value", "42.99"}
  }}
};
{% endhighlight %}

As cool as the applications of  braced initialisation are, support seems to be rather inconsistent. Arne Mertz has some [strong advice](http://arne-mertz.de/2015/02/type-deduction-and-braced-initializers/) about this feature:

> Don't use braced initializers together with type deduction.

I've taken the following examples straight from his article:

{% highlight cpp %}
//C++14
auto a = { 1, 2, 3 }; //initializer_list<int>
auto b { 42 };        //ditto
{% endhighlight %}

Another block, referencing a [new proposal for C++17](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3922.html):

{% highlight cpp %}
//N3922
auto a = { 1, 2, 3 }; //std::initializer_list<int>, as before
auto b { 42 };        //NEW: int
auto c { 42, 7 };     //NEW: compile error
{% endhighlight %}

MSVC already supports N3922, but may revoke this if N3922 fails to be added to the C++17 standard.

Not only is support for braced initialisation inconsistent across compilers, it's inconsistent across standards. It really feels like a beta release, and I have to agree with Arne's recommendation.

For further information on braced initialisation, see Item 7 of Scott Meyers' [Effective Modern C++](http://shop.oreilly.com/product/0636920033707.do).

## Correctness & Safety

The games industry seems to take a rather cavalier approach to compiler warnings, often disabling a error codes relating to implicit type conversions simply to 'make life easier'. [Compiler warnings are errors](https://channel9.msdn.com/Events/GoingNative/GoingNative-2012/Clang-Defending-C-from-Murphy-s-Million-Monkeys), and should be treated as such. `auto` is a fantastic tool for improving code correctness, safety and portability.

### Always initialised

It's impossible to use `auto` and have an uninitialised variable, as the type is deduced from construction:

{% highlight cpp %}
int x; 			// undefined behaviour
auto y = 5;		// well defined
auto z = 7u;	// well defined, unsigned
{% endhighlight %}

### Narrowing

From [Microsoft](https://msdn.microsoft.com/en-us/library/hh279667.aspx), formatted for emphasis:

> The compiler performs narrowing conversions implicitly, but it warns you about potential data loss. **Take these warnings very seriously**. If you are certain that no data loss will occur because the values in the larger variable will always fit in the smaller variable, then **add an explicit cast** so that the compiler will no longer issue a warning.

Consider the [following code](http://herbsutter.com/2013/06/13/gotw-93-solution-auto-variables-part-2/):

{% highlight cpp %}
// x and y are of some built-in integral type
int total = x + y;
{% endhighlight %}

If `x` or `y` are larger than an `int` a coercion will occur. The problem gets worse when you consider that `x` or `y` may currently be of type `int` but could change in a future refactor or platform change, and worse still if you have these warnings disabled. `auto` guarantees no narrowing conversions as the compiler will automatically choose the correct type.

Like many game developers, I've written code for different platforms.

What's wrong with [this familiar pattern](http://adamromanek.blogspot.co.uk/2014/11/the-auto-keyword-versus-portability.html?m=1)?:

{% highlight cpp %}
unsigned int size = array.Size();
{% endhighlight %}

A container's size is of type Container::Size, not `unsigned int` and can be different across platforms.  Usually, this would produce a compiler warning, unless you work at a company that disables them (cough cough, the games industry). Using `auto` allows you to sidestep platform specific implementation details never make a mistake again:

{% highlight cpp %}
auto size = array.Size();
{% endhighlight %}

## Readability

### Consistency

`auto` makes code consistent. Consistent code is easy to read, and easy to understand.

Uniform Initialisation is a concept of modern C++, aiming to make variable declaration a more consistent experience. Here is a selection of methods:

{% highlight cpp %}
int a; // unitialised
float b = 42.0; // narrowing
unsigned long c = 15;
const char* bob = "Bob";
std::string str("Fred");
Type t(); // most vexing parse
std::chrono::milliseconds time = 42.1;
std::pair<Key, Value> pair = map.get(...);
HeapType heapObj = new HeapType();
Custom::Types::Speed::MPH speed = 88.8;
{% endhighlight %}

Moving the type definition to the right of the assignment unifies variable initialisation mechanisms: default and copy constructors, initialiser lists, user and library literals, and function returns:

{% highlight cpp %}
auto a = 42;
auto b = 42.0f;
auto c = 15ul;
auto bob = "Bob";
auto str = std::string{"Fred"};
auto str = "Fred"s;
auto t = Type();
auto time = 42.1ms;
auto pair = map.get(...);
auto heapObj = std::make_unique<HeapType>();
auto speed = 88.8mph;
{% endhighlight %}

>Name on the left, type on the right. It's so simple.

Using `auto` means that code lines up more frequently, which looks nice and gives me my OCD fix for the day.

### Intent

Variable declarations describe intent, and `auto`, when combined with `const` and `&`, makes it easy to express how we intend to use them.

Consider the following block:

{% highlight cpp %}
const auto value = 17u;
const auto& obj = GetObj();

auto result = Calculation(obj, otherObj, value);
{% endhighlight %}

You can see that `obj` is both `const` and a reference. This shows that it will be used in a read only context, likely to calculate something or copy data from. Here, `auto` makes it easy to spot when a variable is of `const` or reference type. You'll really start to notice how useful this is when declaring multiple local variables.

### Names

The purpose of a variable should be defined in it's name, and not it's type.

{% highlight cpp %}
Weapon weapon = Factory.GetWeapon();
{% endhighlight %}

Using `auto` simplifies the definition:

{% highlight cpp %}
auto weapon = Factory.GetWeapon();
{% endhighlight %}

Many programmers shorten the name of variables. It's of course down to personal style, but I think that names should be descriptive as possible. This could be partly down to the fact that C++ programmers are so used to having to specify type, followed by a name, and then the type once more if it's on the heap.

{% highlight cpp %}
Object object = new Object();
{% endhighlight %}

Using a modern approach means the type is only defined once:

{% highlight cpp %}
auto object = make_unique<Object>();
{% endhighlight %}

`auto` also helps with using nested namespace types:

{% highlight cpp %}
My::Custom::Namespaced::Object obj = GetObj();
{% endhighlight %}

Becomes:

{% highlight cpp %}
auto obj = GetObj();
{% endhighlight %}

Which is not only easier to read but reduces namespace pollution introduced by the `using` directive.

## When not to `auto`

### When you can't

Types that can't be moved:

{% highlight cpp %}
auto atom = std::atomic<int>{}; // compilation error
{% endhighlight %}

### When you shouldn't

Types that are expensive to move:

{% highlight cpp %}
auto array = std::array<int, 50>();
{% endhighlight %}

## Conclusion

* `auto` makes code mode readable.
* `auto` makes code safe, correct and portable.
* Let `auto` focus on types, it leaves you free to focus on how you are going to use them.
* Let `auto` do the heavy lifting. The compiler is always correct, are you?
* Use casts or constructors if you want to use an explicit type.
* `auto` can`t be used with immovable types
* `auto` shouldn't be used with expensive to move types

## Additional references

* Järvi, Soustroup, Dos Reis. [Deducing the type of variable from its initializer expression](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1984.pdf).
* Bjarne Soustroup. [C++11 FAQ](http://www.stroustrup.com/C++11FAQ.html#auto).
* Scott Meyers. [Effective Modern C++](http://shop.oreilly.com/product/0636920033707.do).
* Herb Sutter. CppCon 2014: Back to the Basics! Essentials of Modern C++ Style. [Video](https://www.youtube.com/watch?v=xnqTKD8uD64) and [slides](https://github.com/CppCon/CppCon2014/blob/master/Presentations/Back%20to%20the%20Basics!%20Essentials%20of%20Modern%20C%2B%2B%20Style/Back%20to%20the%20Basics!%20Essentials%20of%20Modern%20C%2B%2B%20Style%20-%20Herb%20Sutter%20-%20CppCon%202014.pdf).
* Adam Romanek. [The `auto` keyword versus portability](http://adamromanek.blogspot.co.uk/2014/11/the-auto-keyword-versus-portability.html?m=1).
* Arne Mertz. [Type Deduction and Braced Initializers](http://arne-mertz.de/2015/02/type-deduction-and-braced-initializers/).
* Herb Sutter. [Guru of the Week](http://herbsutter.com/gotw/) blog posts ([one](http://herbsutter.com/2013/06/07/gotw-92-solution-auto-variables-part-1/), [two](http://herbsutter.com/2013/06/13/gotw-93-solution-auto-variables-part-2/), [three](http://herbsutter.com/2013/08/12/gotw-94-solution-aaa-style-almost-always-auto/)).
* LLVM. [Coding Standards](http://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable).

---


text:
from nodev.specs import generic

def test_mapping_contains(mapping_contains=generic.mapping_contains):
    assert mapping_contains({'key': 'value'}, 'key')
    assert mapping_contains({'key': 'value'}, 'value')
    assert not mapping_contains({'key': 'value'}, 'other')

def test_strict_contains(strict_contains=generic.strict_contains):
    assert strict_contains('value', 'v')
    assert not strict_contains('value', 'k')
    assert not strict_contains('value', 'val')

def test_instance_contains_attributes(instance_contains=generic.instance_contains):
    # instance attribute
    class A(object):
        pass
    instance = A()
    instance.attr = 'value'
    assert instance_contains(instance, 'value')
    assert not instance_contains(instance, 'other')

    # class attribute
    class C(object):
        attr = 'value'
    instance = C()
    assert instance_contains(instance, 'value')
    assert not instance_contains(instance, 'other')

def test_instance_contains_properties(instance_contains=generic.instance_contains):
    class B(object):
        @property
        def attr(self):
            return 'value'
    instance = B()
    assert instance_contains(instance, 'value')
    assert not instance_contains(instance, 'other')

def test_contains(contains=generic.contains):
    assert contains('value', 'value')
    test_strict_contains(generic.contains)
    assert contains(['value'], 'value')
    assert contains(iter(['value']), 'value')
    test_mapping_contains(contains)
    test_instance_contains_attributes(contains)
    test_instance_contains_properties(contains)

def test_flat_contains(flat_contains=generic.flat_contains):
    test_contains(flat_contains)
    assert flat_contains([('key', 'value')], 'value')
    assert flat_contains({'key': ['value']}, 'value')

    class C(object):
        attr = {'key': 'value'}

    assert flat_contains(C(), 'value')

def test_container(container=generic.Container):
    assert 'value' in container('value')
    assert 'other' not in container('value')

    assert 'value' in container(iter(['value']))
    assert 'other' not in container(iter(['value']))

    assert 'value' in container({'key': 'value'})
    assert 'other' not in container({'key': 'value'})

    assert 'v' in container('value')
    assert 'k' not in container('value')

    # instance attributes
    class A(object):
        pass
    instance = A()
    instance.attr = 'value'
    assert 'value' in container(instance)
    assert 'other' not in container(instance)

    # instance properties
    class B(object):
        @property
        def attr(self):
            return 'value'
    instance = B()
    assert 'value' in container(instance)
    assert 'other' not in container(instance)

    # class attributes
    class C(object):
        attr = 'value'
    instance = C()
    assert 'value' in container(instance)
    assert 'other' not in container(instance)

def test_flat_container():
    test_container(generic.FlatContainer)

    assert 'value' in generic.FlatContainer([('value', 0)])
    assert 'value' in generic.FlatContainer(iter([('value', 0)]))

redpajama_set_name: RedPajamaGithub


text:
..  _browse files:

Browsing, opening, and saving files from |Office iOS|
=====================================================

Once you have finished integration with |Office iOS|, users will be able to browse, open and save files from your
storage location directly in the Office apps as well as open their Office files from your storage location. This
section describes the user experience for browsing, opening and saving files from |Office iOS|.

Open from |Office iOS|
----------------------

#. User selects :guilabel:`Add a Place` in their Office app.

   .. figure:: ../images/scenario_add.png
      :alt: A screenshot that shows adding a place in the iOS backstage.

#. A list of places is displayed and the user selects :guilabel:`Contoso`.

   .. figure:: ../images/scenario_add2.png
      :alt: A screenshot that shows choosing a place from an available list.

#. The user goes through Contoso's OAuth 2.0 flow.

   .. figure:: ../images/scenario_oauth.png
      :alt: A screenshot that shows an OAuth authentication screen.

#. The user can now browse through files stored on Contoso and open them.

   .. figure:: ../images/scenario_browse.png
      :alt: A screenshot that shows browsing a place after it has been added in the backstage.

#. The user can edit the file.

   .. figure:: ../images/scenario_edit.png
      :alt: A screenshot that shows editing a file in |Office iOS|.

Open from your Cloud Storage App
--------------------------------

1. User browses to a file on your iOS app.

   .. figure:: ../images/scenario_app_browse.png
      :alt: A screenshot that shows browsing in a storage app.

2. User selects Edit.

   .. figure:: ../images/scenario_preview.png
      :alt: A screenshot that shows previewing the file within a storage app.

 ..  note::
       If you do not have an in-app preview, you may open Office in other screens.

3. The file is opened in Office and any saves go back to your service directly.

   .. figure:: ../images/scenario_edit.png
      :alt: A screenshot that shows editing a file in |Office iOS|.


text:
package com.pliu.logconsumerbatch

import org.apache.spark.SparkContext
import org.apache.spark.sql.SparkSession
import org.apache.spark.streaming.{Seconds, StreamingContext}
import org.apache.spark.streaming.eventhubs.EventHubsUtils
import org.apache.spark.sql.SQLContext
import org.apache.spark.sql.SaveMode
import org.apache.spark.sql.functions._
import java.util.Calendar
import java.util.TimeZone
import org.apache.http._
import org.apache.http.client._
import org.apache.http.client.methods.HttpPost
import org.apache.http.impl.client.DefaultHttpClient
import org.apache.http.entity.StringEntity
import com.typesafe.config._

object GeoLogConsumerBatch {
  def main(args: Array[String]): Unit = {
    val appconf = ConfigFactory.load("logBatch")
    val eventHubNameSpace = appconf.getString("logBatch.eventHubNameSpace")
    val eventHubName = appconf.getString("logBatch.eventHubName")
    val eventHubPolicyName = appconf.getString("logBatch.eventHubPolicyName")
    val eventHubPolicyKey = appconf.getString("logBatch.eventHubPolicyKey")
    val eventHubPartitionCount = appconf.getString("logBatch.eventHubPartitionCount")
    val eventHubConsumerGroup = appconf.getString("logBatch.eventHubConsumerGroup")
    val progressDir = appconf.getString("logBatch.progressDir")
    val streamWindowInSeconds = appconf.getInt("logBatch.streamWindowInSeconds")
    val hdfsOutputBaseDir = appconf.getString("logBatch.hdfsOutputBaseDir")

    val geoDir = hdfsOutputBaseDir + "/geo"
    val purchaseDir = hdfsOutputBaseDir + "/purchase"
    val levelDir = hdfsOutputBaseDir + "/level"

    val eventhubParameters = Map[String, String] (
      "eventhubs.policyname" -> eventHubPolicyName,
      "eventhubs.policykey" -> eventHubPolicyKey,
      "eventhubs.namespace" -> eventHubNameSpace,
      "eventhubs.name" -> eventHubName,
      "eventhubs.partition.count" -> eventHubPartitionCount,
      "eventhubs.consumergroup" -> eventHubConsumerGroup
    )

    val sc = new SparkContext
    val ssc = new StreamingContext(sc, Seconds(streamWindowInSeconds))
    val stream = EventHubsUtils.createDirectStreams(
      ssc,
      eventHubNameSpace,
      progressDir,
      Map(eventHubName -> eventhubParameters))
    val lines = stream.map(msg => new String(msg.getBody))

    lines.foreachRDD { rdd =>
      val spark = SparkSession.builder.getOrCreate
      import spark.implicits._

      try {
        val rawDF = spark.read.json(rdd)
        val tsDF = rawDF
                    .withColumn("eventts", rawDF("eventTime").cast("timestamp")).drop(rawDF("eventTime"))
                    .createOrReplaceTempView("logs")
        val gameStart = spark.sql("select eventts, playerId, sessionId, eventParams.city, eventParams.lat, eventParams.lon from logs where eventType = 'gameStart' ")
        val itemPurchased = spark.sql("select eventts, playerId, sessionId, eventParams.item, eventParams.quantity, eventParams.price from logs where eventType = 'itemPurchased' ")
        val levelReached = spark.sql("select eventts, playerId, sessionId, eventParams.level from logs where eventType = 'levelReached' ")
        gameStart.write.mode(SaveMode.Append).parquet(geoDir)
        itemPurchased.write.mode(SaveMode.Append).parquet(purchaseDir)
        levelReached.write.mode(SaveMode.Append).parquet(levelDir)
      } catch {
        case e: Exception => println(e.getMessage())
      }
    }

    ssc.start
    ssc.awaitTermination()
  }
}


text:
import os
import sys
from caffe.proto import caffe_pb2

def toPrototxt(modelName, deployName):

    with open(modelName, 'rb') as f:
        caffemodel = caffe_pb2.NetParameter()
        caffemodel.ParseFromString(f.read())

    for item in caffemodel.layer:
        item.ClearField('blobs')

    with open(deployName, 'w') as f:
        f.write(str(caffemodel))

if __name__ == '__main__':

    toPrototxt(sys.argv[1], sys.argv[2])


text:
require('../../../modules/es.array.fill');

module.exports = require('../../../internals/entry-virtual')('Array').fill;


text:
// The original source for this code is
// Copyright (c) 2011, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <AvailabilityMacros.h>
#include <malloc/malloc.h>

static kern_return_t enumerator(task_t, void *, unsigned, vm_address_t,
                                memory_reader_t, vm_range_recorder_t)
{
    return KERN_FAILURE;
}

static size_t good_size(malloc_zone_t *, size_t size)
{
    return size;
}

static boolean_t zone_check(malloc_zone_t *) /* Consistency checker */
{
    return true;
}

static void zone_print(malloc_zone_t *, boolean_t) { }
static void zone_log(malloc_zone_t *, void *) {}
static void zone_force_lock(malloc_zone_t *) {}
static void zone_force_unlock(malloc_zone_t *) {}

static void zone_statistics(malloc_zone_t *, malloc_statistics_t *s)
{
    s->blocks_in_use = 0;
    s->size_in_use = s->max_size_in_use = s->size_allocated = 0;
}

static boolean_t zone_locked(malloc_zone_t *)
{
    return false;
}

static boolean_t impl_zone_enable_discharge_checking(malloc_zone_t *)
{
    return false;
}

static void impl_zone_disable_discharge_checking(malloc_zone_t *) {}
static void impl_zone_discharge(malloc_zone_t *, void *) {}
static void impl_zone_destroy(struct _malloc_zone_t *) {}

/* note: impl_malloc_usable_size() is called for each free() call, so it must be fast */
static size_t impl_malloc_usable_size(struct _malloc_zone_t *, const void *ptr)
{
    // malloc_usable_size() is used by OS X to recognize which memory manager
    // allocated the address, so our wrapper must not redirect to the original function.
    return __TBB_malloc_safer_msize(const_cast<void*>(ptr), NULL);
}

static void *impl_malloc(struct _malloc_zone_t *, size_t size);
static void *impl_calloc(struct _malloc_zone_t *, size_t num_items, size_t size);
static void *impl_valloc(struct _malloc_zone_t *, size_t size);
static void impl_free(struct _malloc_zone_t *, void *ptr);
static void *impl_realloc(struct _malloc_zone_t *, void *ptr, size_t size);
static void *impl_memalign(struct _malloc_zone_t *, size_t alignment, size_t size);

/* ptr is in zone and have reported size */
static void impl_free_definite_size(struct _malloc_zone_t*, void *ptr, size_t size)
{
    __TBB_malloc_free_definite_size(ptr, size);
}

/* Empty out caches in the face of memory pressure. */
static size_t impl_pressure_relief(struct _malloc_zone_t *, size_t goal)
{
    return 0;
}

static malloc_zone_t *system_zone;

struct DoMallocReplacement {
    DoMallocReplacement() {
        static malloc_introspection_t introspect;
        memset(&introspect, 0, sizeof(malloc_introspection_t));
        static malloc_zone_t zone;
        memset(&zone, 0, sizeof(malloc_zone_t));

        introspect.enumerator = &enumerator;
        introspect.good_size = &good_size;
        introspect.check = &zone_check;
        introspect.print = &zone_print;
        introspect.log = zone_log;
        introspect.force_lock = &zone_force_lock;
        introspect.force_unlock = &zone_force_unlock;
        introspect.statistics = zone_statistics;
        introspect.zone_locked = &zone_locked;
        introspect.enable_discharge_checking = &impl_zone_enable_discharge_checking;
        introspect.disable_discharge_checking = &impl_zone_disable_discharge_checking;
        introspect.discharge = &impl_zone_discharge;

        zone.size = &impl_malloc_usable_size;
        zone.malloc = &impl_malloc;
        zone.calloc = &impl_calloc;
        zone.valloc = &impl_valloc;
        zone.free = &impl_free;
        zone.realloc = &impl_realloc;
        zone.destroy = &impl_zone_destroy;
        zone.zone_name = "tbbmalloc";
        zone.introspect = &introspect;
        zone.version = 8;
        zone.memalign = impl_memalign;
        zone.free_definite_size = &impl_free_definite_size;
        zone.pressure_relief = &impl_pressure_relief;

        // make sure that default purgeable zone is initialized
        malloc_default_purgeable_zone();
        // after unregistration of system zone, our zone became default
        malloc_zone_register(&zone);
        system_zone = malloc_default_zone();
        malloc_zone_unregister(system_zone);
        malloc_zone_register(system_zone);
    }
};

static DoMallocReplacement doMallocReplacement;


text:
package ieg.prefuse.action.layout;

import java.util.Iterator;
import java.util.TreeMap;

import prefuse.data.Tuple;
import prefuse.data.expression.Predicate;
import prefuse.visual.VisualItem;
import prefuse.visual.VisualTable;

/**
 * Adds line plot segments between items of the same category. The segments are
 * saved in a {@link VisualTable} and store the {@link VisualItem}s of their
 * start and end points. The action needs to run only once; unless new points
 * are added.
 *
 *

 * Added: 2013-03-24 / AR (based on work by AR and TT)

 * Modifications: 2012-0X-XX / XX / ...
 *

 *
 * @author Alexander Rind (based on work conducted in VisuExplore)
 * @see ieg.prefuse.action.layout.LinePlotLayout
 */
public class CategoryLinePlotAction extends LinePlotAction {

    protected String categoryField = null;
    protected Predicate missingValue = null;

    /**
     * Adds line plot segments between items of the same category.
     *
     * @param group
     *            the new visual table containing line segments
     * @param source
     *            the visual table containing points
     * @param categoryField
     *            the field name by which lines are to be distinguished
     */
    public CategoryLinePlotAction(String group, String source,
            String categoryField) {
        super(group, source);
        this.categoryField = categoryField;
    }

    @SuppressWarnings("rawtypes")
    @Override
    protected void connectPoints(VisualTable lines, Iterator points) {
        // insert a column with category into line table (if not there yet)
        if (lines.getColumn(categoryField) == null) {
			Iterator tuples = m_vis.getGroup(m_src).tuples();
			if (tuples.hasNext()) {
				// we try to copy the column type from 1st row of source
				Tuple firstTuple = (Tuple) tuples.next();
				lines.addColumn(categoryField, firstTuple.getColumnType(categoryField));
			} else {
				// default to String
				lines.addColumn(categoryField, String.class);
			}
        }

        // remember previous node for each time series
        TreeMap<Object, VisualItem> prevTupleMap = new TreeMap<Object, VisualItem>();

        while (points.hasNext()) {
            VisualItem vi = (VisualItem) points.next();
            Object code = categoryField != null ? vi.get(categoryField)
                    : "default";

            if (missingValue != null && missingValue.getBoolean(vi)) {
                // skip this tuple and interrupt the line plot
                prevTupleMap.remove(code);
                continue;
            }

            // connect if possible
            if (prevTupleMap.containsKey(code)) {
                VisualItem line = lines.addItem();
                line.set("v1", prevTupleMap.get(code));
                line.set("v2", vi);
                line.setString(categoryField, String.valueOf(code));
            }

            // remember node for connection
            prevTupleMap.put(code, vi);
        }
    }

    public String getCategoryField() {
        return categoryField;
    }

    public void setCategoryField(String categoryField) {
        this.categoryField = categoryField;
    }

    public Predicate getMissingValue() {
        return missingValue;
    }

    public void setMissingValue(Predicate missingValue) {
        this.missingValue = missingValue;
    }
}


text:
package br.inpe.cap.apache;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.repodriller.RepoDriller;
import org.repodriller.RepositoryMining;
import org.repodriller.Study;
import org.repodriller.filter.range.Commits;
import org.repodriller.persistence.csv.CSVFile;
import org.repodriller.scm.GitRepository;

import br.inpe.cap.auxiliar.MultipleCSVFile;

public class ApacheProjectsVersionEvolutionStudy implements Study {

	private static final int THREADS_FOR_REPOSITORIES = 10;
	private static final File GITHUB_DONE_FILE = new File("done-github_evolution-HOME.txt");
	private static File EXCEPTION_FILE = new File("exceptions-evolution-HOME.log");

	private static final String STUDY_LOG_PATH = "." + File.separator + "study_eval";
	private static final String EVOLUTION_LOG_PATH = STUDY_LOG_PATH + File.separator + "evolutions";

	private static final String APACHE_FILE_PREFIX = "apache_evolution-HOME";
	private static final String APACHE_EVOLUTION_SUMMARY_CSV = STUDY_LOG_PATH + File.separator + APACHE_FILE_PREFIX	+ ".csv";

	private static Logger log;

	public static void main(String[] args) throws IOException {
		System.setProperty("git.maxfiles", "2000");
		System.setProperty("logfilename", APACHE_FILE_PREFIX + "_run01");
		log = Logger.getLogger(RepositoryMining.class);
		ApacheEvolutionVisitor.setLogger(log);

		checkRequiredLogFilesAndDirectories();

		new RepoDriller().start(new ApacheProjectsVersionEvolutionStudy());
		System.out.println("Finish!");
	}

	public void execute() {
		try {

			String rootApacheStudiesPath = "E:\\metricminer2_studies\\";
			List<String> gitRepoDirs = getRepositoryExceptDoneDirs(rootApacheStudiesPath);

			ExecutorService execRepos = Executors.newFixedThreadPool(THREADS_FOR_REPOSITORIES);
			for(String repo : gitRepoDirs) {
				execRepos.submit(() ->
					doMining(repo));
			}

			execRepos.shutdown();
			execRepos.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);

		} catch (Exception e) {
			try {
				String causeMessage = "";
				if(e.getCause() != null)
					causeMessage = e.getCause().getMessage();
				FileUtils.writeStringToFile(EXCEPTION_FILE, e.getMessage() + ". Cause: " + causeMessage +"\n", true);
				System.gc();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		}
	}

	private void doMining(String gitUrl) {
		try {
			new RepositoryMining()
				.in(GitRepository.singleProject(gitUrl))
				.through(Commits.all())
//			.withThreads(3)
				.process(new ApacheEvolutionVisitor(), new MultipleCSVFile(
						new CSVFile(APACHE_EVOLUTION_SUMMARY_CSV, true)
						,
						new CSVFile(EVOLUTION_LOG_PATH
							+ File.separator
							+ "apache-evolution-'"
							+ gitUrl.substring(gitUrl.lastIndexOf(File.separator)+1, gitUrl.length())
							+ "'.csv")))
				.mine();
		} catch (RuntimeException re) {
			log.error(re.getMessage());
		}
		markDone(gitUrl);
		System.gc();
	}

	private List<String> getRepositoryExceptDoneDirs(String rootApacheStudiesPath) throws IOException {
		List<String> allDirsIn = org.repodriller.util.FileUtils.getAllDirsIn(rootApacheStudiesPath);

		FileReader arquivo = new FileReader(GITHUB_DONE_FILE);
		BufferedReader reader = new BufferedReader(arquivo);

		String linha = reader.readLine();
		while (linha != null) {
			allDirsIn.remove(linha);
			linha = reader.readLine();
		}

		reader.close();
		arquivo.close();
		return allDirsIn;
	}

	private void markDone(String gitUrl) {
		try {
			FileUtils.writeStringToFile(GITHUB_DONE_FILE, gitUrl + "\n", true);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private static void checkRequiredLogFilesAndDirectories() throws IOException {
		if(!GITHUB_DONE_FILE.exists()) {
			GITHUB_DONE_FILE.createNewFile();
		}

		File studyPathDir = new File(STUDY_LOG_PATH);
		if(!studyPathDir.exists()) {
			studyPathDir.mkdir();
		}

		File evolutionPathDir = new File(EVOLUTION_LOG_PATH);
		if(!evolutionPathDir.exists()) {
			evolutionPathDir.mkdir();
		}
	}

}


text:
/*
 * Licensed 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.facebook.presto.operator;
import com.facebook.presto.operator.aggregation.AccumulatorFactory;
import com.facebook.presto.operator.aggregation.GroupedAccumulator;
import com.facebook.presto.spi.Page;
import com.facebook.presto.spi.PageBuilder;
import com.facebook.presto.spi.block.BlockBuilder;
import com.facebook.presto.spi.block.BlockBuilderStatus;
import com.facebook.presto.spi.block.LongArrayBlockBuilder;
import com.facebook.presto.spi.block.VariableWidthBlockBuilder;
import com.facebook.presto.spi.type.BigintType;
import com.facebook.presto.spi.type.Type;
import com.facebook.presto.spi.type.VarcharType;
import com.facebook.presto.sql.planner.plan.AggregationNode.Step;
import com.facebook.presto.util.Types;
import com.facebook.presto.sql.planner.Symbol;
import com.facebook.presto.sql.planner.plan.PlanNodeId;
import com.google.common.collect.AbstractIterator;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.primitives.Ints;

//import com.sun.tools.javac.util.Pair;
import com.facebook.presto.spi.type.DoubleType;

import io.airlift.slice.Slice;
import io.airlift.units.DataSize;
import io.airlift.units.DataSize.Unit;
import com.facebook.presto.spi.block.Block;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;

import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.MultiFields;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.queryparser.ext.Extensions.Pair;

import static com.facebook.presto.operator.GroupByHash.createGroupByHash;
import static com.facebook.presto.spi.type.BigintType.BIGINT;
import static com.facebook.presto.spi.type.DoubleType.DOUBLE;
import static com.facebook.presto.spi.type.VarcharType.VARCHAR;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;

import java.io.IOException;
import java.nio.file.Paths;

public class HashAggregationOperator
        implements Operator
{
    public static class HashAggregationOperatorFactory
            implements OperatorFactory
    {
        private final int operatorId;
        private final PlanNodeId planNodeId;
        private final List<Type> groupByTypes;
        private final List<Integer> groupByChannels;
        private final Step step;
        private final List<AccumulatorFactory> accumulatorFactories;
        private final Optional<Integer> hashChannel;

        private final int expectedGroups;
        private final List<Type> types;
        private boolean closed;
        private final long maxPartialMemory;

        //added by cubeli
        private Map<Symbol, Integer> outputMappings;
        private Map<String, String> accumulatTypeAndColumnNameMap;
        private List<Symbol> groupByKeys;

        public HashAggregationOperatorFactory(
                int operatorId,
                PlanNodeId planNodeId,
                List<? extends Type> groupByTypes,
                List<Integer> groupByChannels,
                Step step,
                List<AccumulatorFactory> accumulatorFactories,
                Optional<Integer> hashChannel,
                int expectedGroups,
                DataSize maxPartialMemory,
                Map<Symbol, Integer> outputMappings,
                Map<String, String> accumulatTypeAndColumnNameMap,
                List<Symbol> groupByKeys
                )
        {
            this.operatorId = operatorId;
            this.planNodeId = requireNonNull(planNodeId, "planNodeId is null");
            this.hashChannel = requireNonNull(hashChannel, "hashChannel is null");
            this.groupByTypes = ImmutableList.copyOf(groupByTypes);
            this.groupByChannels = ImmutableList.copyOf(groupByChannels);
            this.step = step;
            this.accumulatorFactories = ImmutableList.copyOf(accumulatorFactories);
            this.expectedGroups = expectedGroups;
            this.maxPartialMemory = requireNonNull(maxPartialMemory, "maxPartialMemory is null").toBytes();

            this.types = toTypes(groupByTypes, step, accumulatorFactories, hashChannel);

            //added by cubeli
            this.outputMappings = outputMappings;
            this.accumulatTypeAndColumnNameMap = accumulatTypeAndColumnNameMap;
            this.groupByKeys = groupByKeys;
        }

        @Override
        public List<Type> getTypes()
        {
            return types;
        }

        @Override
        public Operator createOperator(DriverContext driverContext)
        {
            checkState(!closed, "Factory is already closed");

            OperatorContext operatorContext;
            if (step.isOutputPartial()) {
                operatorContext = driverContext.addOperatorContext(operatorId, planNodeId, HashAggregationOperator.class.getSimpleName(), maxPartialMemory);
            }
            else {
                operatorContext = driverContext.addOperatorContext(operatorId, planNodeId, HashAggregationOperator.class.getSimpleName());
            }
            HashAggregationOperator hashAggregationOperator = new HashAggregationOperator(
                    operatorContext,
                    groupByTypes,
                    groupByChannels,
                    step,
                    accumulatorFactories,
                    hashChannel,
                    expectedGroups,
                    outputMappings,
                    accumulatTypeAndColumnNameMap,
                    groupByKeys);
            return hashAggregationOperator;
        }

        @Override
        public void close()
        {
            closed = true;
        }

        @Override
        public OperatorFactory duplicate()
        {
            return new HashAggregationOperatorFactory(
                    operatorId,
                    planNodeId,
                    groupByTypes,
                    groupByChannels,
                    step,
                    accumulatorFactories,
                    hashChannel,
                    expectedGroups,
                    new DataSize(maxPartialMemory, Unit.BYTE),
                    outputMappings,
                    accumulatTypeAndColumnNameMap,
                    groupByKeys);
        }
    }

    private final OperatorContext operatorContext;
    private final List<Type> groupByTypes;
    private final List<Integer> groupByChannels;
    private final Step step;
    private final List<AccumulatorFactory> accumulatorFactories;
    private final Optional<Integer> hashChannel;
    private final int expectedGroups;

    private final List<Type> types;

    private GroupByHashAggregationBuilder aggregationBuilder;
    private Iterator<Page> outputIterator;
    private boolean finishing;

    //added by cubeli for lucene
    private Map<Symbol, Integer> outputMappings;
    private Map<String, String> accumulatTypeAndColumnNameMap;
    private List<Symbol> groupByKeys;
    public static boolean readLucene = false;

    @SuppressWarnings("unchecked")
	public HashAggregationOperator(
            OperatorContext operatorContext,
            List<Type> groupByTypes,
            List<Integer> groupByChannels,
            Step step,
            List<AccumulatorFactory> accumulatorFactories,
            Optional<Integer> hashChannel,
            int expectedGroups,
            Map<Symbol, Integer> outputMappings,
            Map<String, String> accumulatTypeAndColumnNameMap,
            List<Symbol> groupByKeys)
    {
        this.operatorContext = requireNonNull(operatorContext, "operatorContext is null");
        requireNonNull(step, "step is null");
        requireNonNull(accumulatorFactories, "accumulatorFactories is null");
        requireNonNull(operatorContext, "operatorContext is null");

        this.groupByTypes = ImmutableList.copyOf(groupByTypes);
        this.groupByChannels = ImmutableList.copyOf(groupByChannels);
        this.accumulatorFactories = ImmutableList.copyOf(accumulatorFactories);
        this.hashChannel = requireNonNull(hashChannel, "hashChannel is null");
        this.step = step;
        this.expectedGroups = expectedGroups;
        this.types = toTypes(groupByTypes, step, accumulatorFactories, hashChannel);

        //added by cubeli
        this.outputMappings = outputMappings;
        this.accumulatTypeAndColumnNameMap = accumulatTypeAndColumnNameMap;
        this.groupByKeys = groupByKeys;

    }

    @Override
    public OperatorContext getOperatorContext()
    {
        return operatorContext;
    }

    @Override
    public List<Type> getTypes()
    {
        return types;
    }

    @Override
    public void finish()
    {
        finishing = true;
    }

    @Override
    public boolean isFinished()
    {
        return finishing && aggregationBuilder == null && (outputIterator == null || !outputIterator.hasNext());
    }

    @Override
    public boolean needsInput()
    {
        return !finishing && outputIterator == null && (aggregationBuilder == null || !aggregationBuilder.isFull());
    }

    @Override
    public void addInput(Page page)
    {
        checkState(!finishing, "Operator is already finishing");
        requireNonNull(page, "page is null");
        if (aggregationBuilder == null) {
            aggregationBuilder = new GroupByHashAggregationBuilder(
                    accumulatorFactories,
                    step,
                    expectedGroups,
                    groupByTypes,
                    groupByChannels,
                    hashChannel,
                    operatorContext);

            // assume initial aggregationBuilder is not full
        }
        else {
            checkState(!aggregationBuilder.isFull(), "Aggregation buffer is full");
        }

        /*
        * modified by cubeli for lucene
        * if invoke processPage(page) every time, the partial accumulation result will be
        * accumulated, and the incorrect result will be got in the final accumulation
        */
//        if(!readLucene){
//
//        	readLucene = true;
        	aggregationBuilder.processPage(page);
//        }

    }

//    @Override
//    public Page getOutput()
//    {
//        if (outputIterator == null || !outputIterator.hasNext()) {
//            // current output iterator is done
//            outputIterator = null;
//
//            // no data
//            if (aggregationBuilder == null) {
//                return null;
//            }
//
//            // only flush if we are finishing or the aggregation builder is full
//            if (!finishing && !aggregationBuilder.isFull()) {
//                return null;
//            }
//
//            outputIterator = aggregationBuilder.build();
//            aggregationBuilder = null;
//
//            if (!outputIterator.hasNext()) {
//                // current output iterator is done
//                outputIterator = null;
//                return null;
//            }
//        }
//
//        return outputIterator.next();
//
//    }

	/*
	 * modified by cubeli
	 * the partial accumulation result will be got from read lucene index
	 * the final accumulation result will be got from presto
	 *
	 */
    @Override
    public Page getOutput(){

		if (step == Step.PARTIAL) {

			return getLucenePage4();
		} else {

			return getPrestoPage();
		}

    }

	public Page getPrestoPage() {

		if (outputIterator == null || !outputIterator.hasNext()) {
			// current output iterator is done
			outputIterator = null;

			// no data
			if (aggregationBuilder == null) {
				return null;
			}

			// only flush if we are finishing or the aggregation builder is full
			if (!finishing && !aggregationBuilder.isFull()) {
				return null;
			}

			outputIterator = aggregationBuilder.build();
			aggregationBuilder = null;

			if (!outputIterator.hasNext()) {
				// current output iterator is done
				outputIterator = null;
				return null;
			}
		}

		return outputIterator.next();
	}

    private static List<Type> toTypes(List<? extends Type> groupByType, Step step, List<AccumulatorFactory> factories, Optional<Integer> hashChannel)
    {
        ImmutableList.Builder<Type> types = ImmutableList.builder();
        types.addAll(groupByType);
        if (hashChannel.isPresent()) {
            types.add(BIGINT);
        }
        for (AccumulatorFactory factory : factories) {
            types.add(new Aggregator(factory, step).getType());
        }
        return types.build();
    }

    private  List<Pair<String, String>> getGroupByInfos(Map<Symbol, Integer> outputMappings, Map<String, String> accumulatTypeAndColumnNameMap, List<Symbol> groupByKeys){

    	List<Pair<String, String>> returnList = new ArrayList<Pair<String, String>>();

    	for(int i = 0; i < groupByKeys.size(); i++){

    		Pair<String, String> pair = new Pair<String, String>(groupByKeys.get(i).getName(), types.get(i).getTypeSignature().getBase());
    		returnList.add(pair);
    	}

    	return returnList;
    }

    /*
     * added by cubeli for luecne
     * this method is designed for multi-groupby
     * and it process the hash block as an normal block
     */
    private Page getLucenePage3(){

       	List<List<String>> luceneOrderResult = newTestLuceneResult3();//should be replaced by getLuceneResult3()
    	int entryNum = luceneOrderResult.size();

    	List<Pair<Type, BlockBuilder>> type2Bb = new ArrayList<Pair<Type, BlockBuilder>>();
    	for(Type type : types){

    		BlockBuilder bb = HashAggregationOperator.getBlockbuilderFromType(type, entryNum);
    		type2Bb.add(new Pair<Type, BlockBuilder>(type, bb));
    	}

    	int groupByKeySize = groupByKeys.size();

    	for(int i = 0; i < types.size(); i++){

    		if(i == groupByKeySize){

    			//TODO build this hash block ??
    		}
    		Type type = types.get(i);
			BlockBuilder blockBuilder = type2Bb.get(i).cud;
			for(List<String> line: luceneOrderResult){

				String accuValue = line.get(i);
				if(type instanceof BigintType){

					long value = Long.parseLong(accuValue);
					BIGINT.writeLong(blockBuilder, value);
				}else if(type instanceof VarcharType){

					String value = accuValue;
					VARCHAR.writeString(blockBuilder, value);
				}else if(type instanceof DoubleType){

					Double value = Double.parseDouble(accuValue);
					DOUBLE.writeDouble(blockBuilder, value);
				}
			}
    	}

		BlockBuilder bb[] = new BlockBuilder[type2Bb.size()];
		int idx = 0;
		for(Pair<Type, BlockBuilder> pair : type2Bb){

			BlockBuilder blockBuilder = pair.cud;
			bb[idx++] = blockBuilder;
		}
		Page expectedPage = new Page(bb);
		finishing = true;
    	return expectedPage;
    }

    /*
     * added by cubeli
     * 该方法也用于产生一个page,但是参考的是RecordPageSource的getNextPage方法
     * 因为该方法可以很好的处理不同类型的数据,但是移植过来时去掉了很多异常处理
     */

    public class LuceneGroupByResult{

    	Boolean getBoolean(int columnIdx){

    		return null;
    	}

    	Long getLong(int columnIdx){

    		return null;
    	}

    	Double getDouble(int columnIdx){

    		return null;
    	}

    	Slice getSlice(int columnIdx){

    		return null;
    	}

    	Object getObject(int columnIdx){

    		return null;
    	}
    }
	private Page getLucenePage4(){

		LuceneGroupByResult lgbr = new LuceneGroupByResult();

		int groupByKeySize = groupByKeys.size();
		PageBuilder pageBuilder = new PageBuilder(types);
        for (int column = 0; column < types.size(); column++) {

    		if(column == groupByKeySize){

    			//TODO build this hash block
    		}

            BlockBuilder output = pageBuilder.getBlockBuilder(column);

            Type type = types.get(column);
            Class<?> javaType = type.getJavaType();
            if (javaType == boolean.class) {
                type.writeBoolean(output, lgbr.getBoolean(column));
            }
            else if (javaType == long.class) {
                type.writeLong(output, lgbr.getLong(column));
            }
            else if (javaType == double.class) {
                type.writeDouble(output, lgbr.getDouble(column));
            }
            else if (javaType == Slice.class) {
                Slice slice = lgbr.getSlice(column);
                type.writeSlice(output, slice, 0, slice.length());
            }
            else {
                type.writeObject(output, lgbr.getObject(column));
            }
        }

        Page page = pageBuilder.build();
        pageBuilder.reset();

        return page;

	}

    List<List<String>> newTestLuceneResult3(){

    	List<List<String>> rlList = new ArrayList<List<String>>();
    	List<String> l1 = new ArrayList<String>();
    	l1.add("one");l1.add("111");

    	List<String> l2 = new ArrayList<String>();
    	l2.add("two");l2.add("222");

    	List<String> l3 = new ArrayList<String>();
    	l3.add("three");l3.add("333");

    	rlList.add(l1); rlList.add(l2); rlList.add(l3);

    	return rlList;
    }

    List<List<String>> getLuceneResult3(){

    	//groupby fields infos can be got from getGroupByInfos method
    	//return fields and accu types can be got from accumulatTypeAndColumnNameMap
    	return null;
    }

    @SuppressWarnings("null")
    /*
     * this method are designed for one group by key
     * and it has special processing for hash block
     */
	private Page getLucenePage2() {

    	Page expectedPage = null;

		List<Pair<String, List<String>>> luceneResultList = newTestLuceneResult2();
    	int entryNum = luceneResultList.size();
    	List<Pair<Type, BlockBuilder>> type2Bb = new ArrayList<Pair<Type, BlockBuilder>>() ;

    	int typeIdx = 0;
    	for(Type type : types){

    		if(typeIdx++ == 1){

    			BlockBuilder hashBb = BIGINT.createBlockBuilder(new BlockBuilderStatus(), entryNum);
    			type2Bb.add(new Pair<Type, BlockBuilder>(BIGINT, hashBb));
    			continue;
    		}
    		BlockBuilder bb = getBlockbuilderFromType(type, entryNum);
    		type2Bb.add(new Pair<Type, BlockBuilder>(type, bb));
    	}

		//1.write groupby value
		Type groupByKeyType = type2Bb.get(0).cur;
		BlockBuilder groupByKeyBb = type2Bb.get(0).cud;
		for(Pair<String, List<String>> pair : luceneResultList){

			if(groupByKeyType instanceof BigintType){

				long value = Long.parseLong(pair.cur);
				BIGINT.writeLong(groupByKeyBb, value);
			}else if(groupByKeyType instanceof VarcharType){

				String value = pair.cur;
				VARCHAR.writeString(groupByKeyBb, value);
			}else if(groupByKeyType instanceof DoubleType){

				Double value = Double.parseDouble(pair.cur);
				DOUBLE.writeDouble(groupByKeyBb, value);
			}
		}

		//2.write hash value
		BlockBuilder hashBb = type2Bb.get(1).cud;
		for(int i = 0; i < luceneResultList.size(); i++){

			BIGINT.writeLong(hashBb, i);
		}

		//3.write other column
		for(int i = 2; i < types.size(); i++){

			Type type = types.get(i);
			BlockBuilder blockBuilder = type2Bb.get(i).cud;
			for(Pair<String, List<String>> pair: luceneResultList){

				String accuValue = pair.cud.get(i-2);
				if(type instanceof BigintType){

					long value = Long.parseLong(accuValue);
					BIGINT.writeLong(blockBuilder, value);
				}else if(type instanceof VarcharType){

					String value = accuValue;
					VARCHAR.writeString(blockBuilder, value);
				}else if(type instanceof DoubleType){

					Double value = Double.parseDouble(accuValue);
					DOUBLE.writeDouble(blockBuilder, value);
				}
			}
		}

		BlockBuilder bb[] = new BlockBuilder[type2Bb.size()];
		int idx = 0;
		for(Pair<Type, BlockBuilder> pair : type2Bb){

			BlockBuilder blockBuilder = pair.cud;
			bb[idx++] = blockBuilder;
		}
		expectedPage = new Page(bb);

		finishing = true;
    	return expectedPage;

    }

    List<Pair<String, List<String>>> newTestLuceneResult2(){

    	List<Pair<String, List<String>>> rlList = new ArrayList<Pair<String, List<String>>>();

    	List<String> l1 = new ArrayList<String>();
    	l1.add("111");l1.add("111.1");l1.add("1111");

    	List<String> l2 = new ArrayList<String>();
    	l2.add("222");l2.add("222.2");l2.add("222.22");

    	List<String> l3 = new ArrayList<String>();
    	l3.add("333");l3.add("333.3");l1.add("3333");

    	Pair<String, List<String>> p1 = new Pair<String, List<String>>("cubeli", l1);
    	Pair<String, List<String>> p2 = new Pair<String, List<String>>("yangziying", l2);
    	Pair<String, List<String>> p3 = new Pair<String, List<String>>("litairen", l3);

    	rlList.add(p1);
    	rlList.add(p2);
    	rlList.add(p3);

    	return rlList;
    }

    public  static BlockBuilder getBlockbuilderFromType(Type type, int entryNum) {

    	if(type instanceof BigintType){

    		return BIGINT.createBlockBuilder(new BlockBuilderStatus(), entryNum);
    	}else if(type instanceof VarcharType){

    		return VARCHAR.createBlockBuilder(new BlockBuilderStatus(), entryNum);
    	}else if(type instanceof DoubleType){

    		return DOUBLE.createBlockBuilder(new BlockBuilderStatus(), entryNum);
		}
    	else{

    		return null;
    	}
    }

    //for testing
	private Page getLucenePage() {

		Page expectedPage = null;
		try {
			Map<String, Long> map = getCountResult();
			int expectedEntryNum = map.size();

			BlockBuilder fieldBlockBuilder = VARCHAR.createBlockBuilder(new BlockBuilderStatus(), expectedEntryNum);
			BlockBuilder hashBlockBuilder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), expectedEntryNum);
			BlockBuilder countBlockBuilder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), expectedEntryNum);

			int count = 0;
			for (Entry<String, Long> entry : map.entrySet()) {

				VARCHAR.writeString(fieldBlockBuilder, entry.getKey());
				BIGINT.writeLong(hashBlockBuilder, count++);
				BIGINT.writeLong(countBlockBuilder, entry.getValue());
			}

			expectedPage = new Page(fieldBlockBuilder, hashBlockBuilder, countBlockBuilder);

		} catch (IOException e) {
			e.printStackTrace();
		}

		finishing = true;
		return expectedPage;
	}

    private Map<String, List<String>> getLuceneResult() throws IOException{

    	IndexReader reader = null;
    	Map<String,List<String>> returnMap = new HashMap<String, List<String>>();

    	String groupByColumnName = groupByKeys.get(0).getName();

		try {
			reader = DirectoryReader.open(FSDirectory.open(Paths.get("/home/liyong/workspace-neno/lucenetest/index")));
		} catch (IOException e)
		{
			e.printStackTrace();
		}
		IndexSearcher searcher = new IndexSearcher(reader);

		Terms terms = MultiFields.getTerms(searcher.getIndexReader(), groupByColumnName);
		TermsEnum te = terms.iterator();
		while(te.next() != null){

			List<String> l = new ArrayList<String>();
			String name = te.term().utf8ToString();
			int count = te.docFreq();
			l.add(String.valueOf(count));
			returnMap.put(name, l);
		}

		return returnMap;
    }

	//for testiing
    private Map<String, Long> getCountResult() throws IOException{

    	IndexReader reader = null;
    	Map<String,Long> returnMap = new HashMap<String, Long>();
		try {
			reader = DirectoryReader.open(FSDirectory.open(Paths.get("/home/liyong/workspace-neno/lucenetest/index")));
		} catch (IOException e)
		{
			e.printStackTrace();
		}
		IndexSearcher searcher = new IndexSearcher(reader);

		Terms terms = MultiFields.getTerms(searcher.getIndexReader(), "orderpriority");
		TermsEnum te = terms.iterator();
		while(te.next() != null){

			String name = te.term().utf8ToString();
			int count = te.docFreq();
			returnMap.put(name, Long.valueOf(count));
		}

		return returnMap;
    }

	private Page newLuceneCountPageForTest() {

		// test1 start======================
		BlockBuilder varcharBlockBuilder = VARCHAR.createBlockBuilder(new BlockBuilderStatus(), 5);
		VARCHAR.writeString(varcharBlockBuilder, "2-HIGH");
		VARCHAR.writeString(varcharBlockBuilder, "5-LOW");
		VARCHAR.writeString(varcharBlockBuilder, "1-URGENT");
		VARCHAR.writeString(varcharBlockBuilder, "4-NOT SPECIFIED");
		VARCHAR.writeString(varcharBlockBuilder, "3-MEDIUM");
		Block expectedBlock = varcharBlockBuilder.build();

		BlockBuilder longBlockBuilder1 = BIGINT.createBlockBuilder(new BlockBuilderStatus(), 5);
		BIGINT.writeLong(longBlockBuilder1, 100);
		BIGINT.writeLong(longBlockBuilder1, 101);
		BIGINT.writeLong(longBlockBuilder1, 102);
		BIGINT.writeLong(longBlockBuilder1, 103);
		BIGINT.writeLong(longBlockBuilder1, 104);

		// BlockBuilder longBlockBuilder2 = BIGINT.createBlockBuilder(new
		// BlockBuilderStatus(), 5);
		// BIGINT.writeLong(longBlockBuilder2, 300091);
		// BIGINT.writeLong(longBlockBuilder2, 300589);
		// BIGINT.writeLong(longBlockBuilder2, 300343);
		// BIGINT.writeLong(longBlockBuilder2, 300254);
		// BIGINT.writeLong(longBlockBuilder2, 298723);

		// for sum(totalprice)
		BlockBuilder doubleBlockBuilder2 = DOUBLE.createBlockBuilder(new BlockBuilderStatus(), 5);
		DOUBLE.writeDouble(doubleBlockBuilder2, 2.3);
		DOUBLE.writeDouble(doubleBlockBuilder2, 2.3);
		DOUBLE.writeDouble(doubleBlockBuilder2, 3.4);
		DOUBLE.writeDouble(doubleBlockBuilder2, 4.5);
		DOUBLE.writeDouble(doubleBlockBuilder2, 5.6);

		Page expectedPage = new Page(varcharBlockBuilder, longBlockBuilder1, doubleBlockBuilder2);
		finishing = true;
		return expectedPage;
	}

    private static class GroupByHashAggregationBuilder
    {
        private final GroupByHash groupByHash;
        private final List<Aggregator> aggregators;
        private final OperatorContext operatorContext;
        private final boolean partial;

        private GroupByHashAggregationBuilder(
                List<AccumulatorFactory> accumulatorFactories,
                Step step,
                int expectedGroups,
                List<Type> groupByTypes,
                List<Integer> groupByChannels,
                Optional<Integer> hashChannel,
                OperatorContext operatorContext)
        {
            this.groupByHash = createGroupByHash(operatorContext.getSession(), groupByTypes, Ints.toArray(groupByChannels), hashChannel, expectedGroups);
            this.operatorContext = operatorContext;
            this.partial = step.isOutputPartial();

            // wrapper each function with an aggregator
            ImmutableList.Builder<Aggregator> builder = ImmutableList.builder();
            requireNonNull(accumulatorFactories, "accumulatorFactories is null");
            for (int i = 0; i < accumulatorFactories.size(); i++) {
                AccumulatorFactory accumulatorFactory = accumulatorFactories.get(i);
                builder.add(new Aggregator(accumulatorFactory, step));
            }
            aggregators = builder.build();
        }

        private void processPage(Page page)
        {
            if (aggregators.isEmpty()) {
                groupByHash.addPage(page);
                return;
            }

            GroupByIdBlock groupIds = groupByHash.getGroupIds(page);

            for (Aggregator aggregator : aggregators) {
                aggregator.processPage(groupIds, page);
            }
        }

        public boolean isFull()
        {
            long memorySize = groupByHash.getEstimatedSize();
            for (Aggregator aggregator : aggregators) {
                memorySize += aggregator.getEstimatedSize();
            }
            memorySize -= operatorContext.getOperatorPreAllocatedMemory().toBytes();
            if (memorySize < 0) {
                memorySize = 0;
            }
            if (partial) {
                return !operatorContext.trySetMemoryReservation(memorySize);
            }
            else {
                operatorContext.setMemoryReservation(memorySize);
                return false;
            }
        }

        public Iterator<Page> build()
        {
            List<Type> types = new ArrayList<>(groupByHash.getTypes());
            for (Aggregator aggregator : aggregators) {
                types.add(aggregator.getType());
            }

            final PageBuilder pageBuilder = new PageBuilder(types);
            return new AbstractIterator<Page>()
            {
                private final int groupCount = groupByHash.getGroupCount();
                private int groupId;

                @Override
                protected Page computeNext()
                {
                    if (groupId >= groupCount) {
                        return endOfData();
                    }

                    pageBuilder.reset();

                    List<Type> types = groupByHash.getTypes();
                    while (!pageBuilder.isFull() && groupId < groupCount) {
                        groupByHash.appendValuesTo(groupId, pageBuilder, 0);

                        pageBuilder.declarePosition();
                        for (int i = 0; i < aggregators.size(); i++) {
                            Aggregator aggregator = aggregators.get(i);
                            BlockBuilder output = pageBuilder.getBlockBuilder(types.size() + i);
                            aggregator.evaluate(groupId, output);
                        }

                        groupId++;
                    }

                    return pageBuilder.build();
                }
            };
        }
    }

    private static class Aggregator
    {
        private final GroupedAccumulator aggregation;
        private final Step step;
        private final int intermediateChannel;

        private Aggregator(AccumulatorFactory accumulatorFactory, Step step)
        {
            if (step.isInputRaw()) {
                intermediateChannel = -1;
                aggregation = accumulatorFactory.createGroupedAccumulator();
            }
            else {
                checkArgument(accumulatorFactory.getInputChannels().size() == 1, "expected 1 input channel for intermediate aggregation");
                intermediateChannel = accumulatorFactory.getInputChannels().get(0);
                aggregation = accumulatorFactory.createGroupedIntermediateAccumulator();
            }
            this.step = step;
        }

        public long getEstimatedSize()
        {
            return aggregation.getEstimatedSize();
        }

        public Type getType()
        {
            if (step.isOutputPartial()) {
                return aggregation.getIntermediateType();
            }
            else {
                return aggregation.getFinalType();
            }
        }

        public void processPage(GroupByIdBlock groupIds, Page page)
        {
            if (step.isInputRaw()) {
                aggregation.addInput(groupIds, page);
            }
            else {
                aggregation.addIntermediate(groupIds, page.getBlock(intermediateChannel));
            }
        }

        public void evaluate(int groupId, BlockBuilder output)
        {
            if (step.isOutputPartial()) {
                aggregation.evaluateIntermediate(groupId, output);
            }
            else {
                aggregation.evaluateFinal(groupId, output);
            }
        }
    }
}


text:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

using Svg;
using Svg.Transforms;

namespace BatchSVG
{
    public partial class Form1 : Form
    {
        List<string> svgFileList;

        public Form1()
        {
            InitializeComponent();
        }

        public void GetSvgFiles(string path)
        {
            foreach (string dir in Directory.GetDirectories(path))
            {
                GetSvgFiles(dir);
            }

            foreach (string file in Directory.GetFiles(path, "*.svg"))
            {
                svgFileList.Add(file);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                string path = folderBrowserDialog1.SelectedPath;
                textBox1.Text = path;

                if (string.IsNullOrEmpty(textBox2.Text))
                {
                    string outPath = Path.Combine(path, "converted");
                    textBox2.Text = outPath;
                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox2.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            svgFileList = new List<string>();
            string source = textBox1.Text;
            string output = textBox2.Text;

            if (!Directory.Exists(output))
                Directory.CreateDirectory(output);

            GetSvgFiles(source);
            int index = 0;

            foreach (string sf in svgFileList)
            {
                string fileName = Path.GetFileNameWithoutExtension(sf);
                using (Bitmap image = new Bitmap((int)numericUpDown1.Value, (int)numericUpDown2.Value))
                {
                    label8.Text = string.Format("Processing image {0} | {1}%", Path.GetFileName(sf), Math.Ceiling(((double)((double)index / (double)svgFileList.Count) * 100)));
                    this.Refresh();

                    SvgDocument doc = SvgDocument.Open(sf);
                    doc.Width = image.Width;
                    doc.Height = image.Height;
                    doc.Draw(image);

                    string of = Path.Combine(output, fileName);

                    if (comboBox1.Text == "PNG")
                        image.Save(of + ".png", ImageFormat.Png);
                    else if (comboBox1.Text == "JPEG")
                        image.Save(of + ".jpg", ImageFormat.Jpeg);
                    else if (comboBox1.Text == "GIF")
                        image.Save(of + ".gif", ImageFormat.Gif);
                    else if (comboBox1.Text == "TIFF")
                        image.Save(of + ".tif", ImageFormat.Tiff);
                    else if (comboBox1.Text == "BMP")
                        image.Save(of + ".bmp", ImageFormat.Bmp);
                    else
                        image.Save(of + ".png", ImageFormat.Png);

                    index++;
                }
            }

            label8.Text = "Finished";
        }
    }
}


text:
import { RootNode } from '../nodes';
import { createConfig } from './config';
import * as tsGen from './tsGen/tsGen';
import * as jsGen from './jsGen/jsGen';
import { language } from '../constants';

export default function generateImpl(rootNode: RootNode): string {
  const config = createConfig(rootNode);
  switch (config.language) {
    case language.typescript:
      return tsGen.generate(rootNode, config);
    case language.javascript:
      return jsGen.generate(rootNode, config);
    default:
      return '/* unsupported language */';
  }
}


text:
<!DOCTYPE html>

    <meta charset="utf-8"/>
    <title>Insure Cars</title>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <link rel="stylesheet" href="../static/css/bootstrap.css" th:href="@{/css/bootstrap.css}" media="screen"/>
    <link rel="stylesheet" href="../static/css/custom.min.css" th:href="@{/css/custom.min.css}"/>
    <link rel="stylesheet" th:href="@{/css/main.css}"/>

Offers

                #
                Type
                Brand
                Color
                VIN
                Seller
                Price
                HIS

                <form th:action="@{/offers}" method="post">

                        Type

                        Brand

                        Color

                        VIN
                        <input type="hidden" name="vin" th:value="${offerAndCar.offer.vin}"/>

                        seller
                        <input type="hidden" name="seller" th:value="${offerAndCar.offer.seller}"/>

                        price
                        <input type="hidden" name="price" th:value="${offerAndCar.offer.price}"/>

                        <button class="btn btn-success">accept</button>

                </form>

No offers pending.


text:
module.exports = function (dex) {
  /**
   *
   * This module provides routines for dealing with geometry.
   *
   * @module dex/geometry
   *
   */
  var geometry = {};

  // square distance between 2 points
  /**
   *
   * This method returns the square distance between two points..
   *
   * @param p1 Point 1
   * @param p2 Point 2
   *
   * @returns {number} The square distance between two points.
   *
   * @memberof dex/geometry
   *
   */
  geometry.getSqDist = function (p1, p2) {
    var dx = p1.x - p2.x,
      dy = p1.y - p2.y;

    return dx * dx + dy * dy;
  };

  // square distance from a point to a segment
  geometry.getSqSegDist = function (p, p1, p2) {

    var x = p1.x,
      y = p1.y,
      dx = p2.x - x,
      dy = p2.y - y;

    if (dx !== 0 || dy !== 0) {

      var t = ((p.x - x) * dx + (p.y - y) * dy) / (dx * dx + dy * dy);

      if (t > 1) {
        x = p2.x;
        y = p2.y;

      } else if (t > 0) {
        x += dx * t;
        y += dy * t;
      }
    }

    dx = p.x - x;
    dy = p.y - y;

    return dx * dx + dy * dy;
  };

  geometry.simplifyRadialDist = function (points, sqTolerance) {

    var prevPoint = points[0],
      newPoints = [prevPoint],
      point;

    for (var i = 1, len = points.length; i < len; i++) {
      point = points[i];

      if (dex.geometry.getSqDist(point, prevPoint) > sqTolerance) {
        newPoints.push(point);
        prevPoint = point;
      }
    }

    if (prevPoint !== point) newPoints.push(point);

    return newPoints;
  };

  geometry.simplifyDPStep = function (points, first, last, sqTolerance, simplified) {
    var maxSqDist = sqTolerance,
      index;

    for (var i = first + 1; i < last; i++) {
      var sqDist = dex.geometry.getSqSegDist(points[i], points[first], points[last]);

      if (sqDist > maxSqDist) {
        index = i;
        maxSqDist = sqDist;
      }
    }

    if (maxSqDist > sqTolerance) {
      if (index - first > 1) dex.geometry.simplifyDPStep(points, first, index, sqTolerance, simplified);
      simplified.push(points[index]);
      if (last - index > 1) dex.geometry.simplifyDPStep(points, index, last, sqTolerance, simplified);
    }
  };

  geometry.simplifyDouglasPeucker = function (points, sqTolerance) {
    var last = points.length - 1;

    var simplified = [points[0]];
    dex.geometry.simplifyDPStep(points, 0, last, sqTolerance, simplified);
    simplified.push(points[last]);

    return simplified;
  };

  // both algorithms combined for awesome performance
  geometry.simplify = function (points, tolerance, highestQuality) {

    if (points.length <= 2) return points;

    var sqTolerance = tolerance !== undefined ? tolerance * tolerance : 1;

    points = highestQuality ? points : dex.geometry.simplifyRadialDist(points, sqTolerance);
    points = dex.geometry.simplifyDouglasPeucker(points, sqTolerance);

    return points;
  };

  geometry.pointInside = function (point, points) {
    // ray-casting algorithm based on
    // http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html

    var x = point[0], y = point[1];

    var inside = false;
    for (var i = 0, j = points.length - 1; i < points.length; j = i++) {
      var xi = points[i][0], yi = points[i][1];
      var xj = points[j][0], yj = points[j][1];

      var intersect = ((yi > y) != (yj > y))
        && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
      if (intersect) inside = !inside;
    }

    return inside;
  };

  geometry.extents = function (points) {
    if (points[0] === undefined || points[0][0] === undefined || points[0][1] === undefined) {
      return undefined;
    }

    var extents = {
      x: {min: points[0][0], max: points[0][0]},
      y: {min: points[0][1], max: points[0][1]}
    };

    points.forEach(function (point) {
      if (extents.x.max < point[0]) {
        extents.x.max = point[0];
      }
      if (extents.y.max < point[1]) {
        extents.y.max = point[1];
      }

      if (extents.x.min > point[0]) {
        extents.x.min = point[0];
      }
      if (extents.y.min > point[1]) {
        extents.y.min = point[1];
      }
    });
    return extents;
  };

  geometry.rasterize = function (points, resolution) {
    var res = resolution || 1.0;
    var extents = dex.geometry.extents(points);
    var x, y;
    var image = [];
    for (y = extents.y.min; y <= extents.y.max; y += res) {
      var scanline = [];
      for (x = extents.x.min; x <= extents.x.max; x += res) {
        scanline.push((dex.geometry.pointInside([x, y], points)) ? 1 : 0);
      }
      image.push(scanline);
    }

    return {
      'image': image,
      'extents': extents,
      'resolution': res
    };
  };

  geometry.maxRect = function (matrix) {
    /*
     Updates maximal rectangle algorithm cache

     @param int[][] matrix 2d array of 1s / 0s rep. game board
     @param int x current cache column
     @param int[] cache
     */
    function updateCache(matrix, x, cache) {
      for (var y = 0; y < rows; y++)
        if (matrix[x][y] == 1)
          cache[y]++;
        else
          cache[y] = 0;
    }

    var bestUpperLeft = {x: -1, y: -1};
    var bestLowerRight = {x: -1, y: -1};

    var cache = new Array(rows + 1), stack = []; // JS arrays have push and pop. Awesome!
    for (var i = 0; i < cache.length; i++)
      cache[i] = 0;

    for (var x = cols - 1; x >= 0; x--) {
      updateCache(matrix, x, cache);
      var width = 0;
      for (var y = 0; y < rows + 1; y++) {
        if (cache[y] > width) {
          stack.push({y: y, width: width});
          width = cache[y];
        }
        if (cache[y] < width) {
          while (true) {
            var pop = stack.pop();
            var y0 = pop.y, w0 = pop.width;
            if (((width * (y - y0)) > area(bestUpperLeft, bestLowerRight)) && (y - y0 >= minQuadY) && (width >= minQuadX)) {
              bestUpperLeft = {x: x, y: y0};
              bestLowerRight = {x: x + width - 1, y: y - 1};
            }
            width = w0;
            if (cache[y] >= width)
              break;
          }
          width = cache[y];
          if (width != 0)
            stack.push({y: y0, width: w0});
        }
      }
    }
    return {
      x: bestUpperLeft.x,
      y: bestUpperLeft.y,
      lenX: bestLowerRight.x - bestUpperLeft.x + 1,
      lenY: bestLowerRight.y - bestUpperLeft.y + 1,
      area: area(bestUpperLeft, bestLowerRight)
    };
  };

  geometry.getRectangularArea = function (upperLeft, lowerRight) {
    if (upperLeft.x > lowerRight.x || upperLeft.y > lowerRight.y)
      return 0;
    return ((lowerRight.x + 1) - (upperLeft.x)) * ((lowerRight.y + 1) - (upperLeft.y));
  };

  return geometry;
};


text:
#include <aws/iam/model/ManagedPolicyDetail.h>
#include <aws/core/utils/xml/XmlSerializer.h>
#include <aws/core/utils/StringUtils.h>
#include <aws/core/utils/memory/stl/AWSStringStream.h>

#include <utility>

using namespace Aws::IAM::Model;
using namespace Aws::Utils::Xml;
using namespace Aws::Utils;

ManagedPolicyDetail::ManagedPolicyDetail() :
    m_policyNameHasBeenSet(false),
    m_policyIdHasBeenSet(false),
    m_arnHasBeenSet(false),
    m_pathHasBeenSet(false),
    m_defaultVersionIdHasBeenSet(false),
    m_attachmentCount(0),
    m_attachmentCountHasBeenSet(false),
    m_isAttachable(false),
    m_isAttachableHasBeenSet(false),
    m_descriptionHasBeenSet(false),
    m_createDate(0.0),
    m_createDateHasBeenSet(false),
    m_updateDate(0.0),
    m_updateDateHasBeenSet(false),
    m_policyVersionListHasBeenSet(false)
{
}

ManagedPolicyDetail::ManagedPolicyDetail(const XmlNode& xmlNode) :
    m_policyNameHasBeenSet(false),
    m_policyIdHasBeenSet(false),
    m_arnHasBeenSet(false),
    m_pathHasBeenSet(false),
    m_defaultVersionIdHasBeenSet(false),
    m_attachmentCount(0),
    m_attachmentCountHasBeenSet(false),
    m_isAttachable(false),
    m_isAttachableHasBeenSet(false),
    m_descriptionHasBeenSet(false),
    m_createDate(0.0),
    m_createDateHasBeenSet(false),
    m_updateDate(0.0),
    m_updateDateHasBeenSet(false),
    m_policyVersionListHasBeenSet(false)
{
  *this = xmlNode;
}

ManagedPolicyDetail& ManagedPolicyDetail::operator =(const XmlNode& xmlNode)
{
  XmlNode resultNode = xmlNode;

  if(!resultNode.IsNull())
  {
    XmlNode policyNameNode = resultNode.FirstChild("PolicyName");
    if(policyNameNode.IsNull())
    {
      policyNameNode = resultNode;
    }

    if(!policyNameNode.IsNull())
    {
      m_policyName = StringUtils::Trim(policyNameNode.GetText().c_str());
      m_policyNameHasBeenSet = true;
    }
    XmlNode policyIdNode = resultNode.FirstChild("PolicyId");
    if(policyIdNode.IsNull())
    {
      policyIdNode = resultNode;
    }

    if(!policyIdNode.IsNull())
    {
      m_policyId = StringUtils::Trim(policyIdNode.GetText().c_str());
      m_policyIdHasBeenSet = true;
    }
    XmlNode arnNode = resultNode.FirstChild("Arn");
    if(arnNode.IsNull())
    {
      arnNode = resultNode;
    }

    if(!arnNode.IsNull())
    {
      m_arn = StringUtils::Trim(arnNode.GetText().c_str());
      m_arnHasBeenSet = true;
    }
    XmlNode pathNode = resultNode.FirstChild("Path");
    if(pathNode.IsNull())
    {
      pathNode = resultNode;
    }

    if(!pathNode.IsNull())
    {
      m_path = StringUtils::Trim(pathNode.GetText().c_str());
      m_pathHasBeenSet = true;
    }
    XmlNode defaultVersionIdNode = resultNode.FirstChild("DefaultVersionId");
    if(defaultVersionIdNode.IsNull())
    {
      defaultVersionIdNode = resultNode;
    }

    if(!defaultVersionIdNode.IsNull())
    {
      m_defaultVersionId = StringUtils::Trim(defaultVersionIdNode.GetText().c_str());
      m_defaultVersionIdHasBeenSet = true;
    }
    XmlNode attachmentCountNode = resultNode.FirstChild("AttachmentCount");
    if(attachmentCountNode.IsNull())
    {
      attachmentCountNode = resultNode;
    }

    if(!attachmentCountNode.IsNull())
    {
      m_attachmentCount = StringUtils::ConvertToInt32(StringUtils::Trim(attachmentCountNode.GetText().c_str()).c_str());
      m_attachmentCountHasBeenSet = true;
    }
    XmlNode isAttachableNode = resultNode.FirstChild("IsAttachable");
    if(isAttachableNode.IsNull())
    {
      isAttachableNode = resultNode;
    }

    if(!isAttachableNode.IsNull())
    {
      m_isAttachable = StringUtils::ConvertToBool(StringUtils::Trim(isAttachableNode.GetText().c_str()).c_str());
      m_isAttachableHasBeenSet = true;
    }
    XmlNode descriptionNode = resultNode.FirstChild("Description");
    if(descriptionNode.IsNull())
    {
      descriptionNode = resultNode;
    }

    if(!descriptionNode.IsNull())
    {
      m_description = StringUtils::Trim(descriptionNode.GetText().c_str());
      m_descriptionHasBeenSet = true;
    }
    XmlNode createDateNode = resultNode.FirstChild("CreateDate");
    if(createDateNode.IsNull())
    {
      createDateNode = resultNode;
    }

    if(!createDateNode.IsNull())
    {
      m_createDate = StringUtils::ConvertToDouble(StringUtils::Trim(createDateNode.GetText().c_str()).c_str());
      m_createDateHasBeenSet = true;
    }
    XmlNode updateDateNode = resultNode.FirstChild("UpdateDate");
    if(updateDateNode.IsNull())
    {
      updateDateNode = resultNode;
    }

    if(!updateDateNode.IsNull())
    {
      m_updateDate = StringUtils::ConvertToDouble(StringUtils::Trim(updateDateNode.GetText().c_str()).c_str());
      m_updateDateHasBeenSet = true;
    }
    XmlNode policyVersionListNode = resultNode.FirstChild("PolicyVersionList");
    if(!policyVersionListNode.IsNull())
    {
      XmlNode policyVersionListMember = policyVersionListNode.FirstChild("member");
      while(!policyVersionListMember.IsNull())
      {
        m_policyVersionList.push_back(policyVersionListMember);
        policyVersionListMember = policyVersionListMember.NextNode("member");
      }

      m_policyVersionListHasBeenSet = true;
    }
  }

  return *this;
}

void ManagedPolicyDetail::OutputToStream(Aws::OStream& oStream, const char* location, unsigned index, const char* locationValue) const
{
  if(m_policyNameHasBeenSet)
  {
      oStream << location << index << locationValue << ".PolicyName=" << StringUtils::URLEncode(m_policyName.c_str()) << "&";
  }
  if(m_policyIdHasBeenSet)
  {
      oStream << location << index << locationValue << ".PolicyId=" << StringUtils::URLEncode(m_policyId.c_str()) << "&";
  }
  if(m_arnHasBeenSet)
  {
      oStream << location << index << locationValue << ".Arn=" << StringUtils::URLEncode(m_arn.c_str()) << "&";
  }
  if(m_pathHasBeenSet)
  {
      oStream << location << index << locationValue << ".Path=" << StringUtils::URLEncode(m_path.c_str()) << "&";
  }
  if(m_defaultVersionIdHasBeenSet)
  {
      oStream << location << index << locationValue << ".DefaultVersionId=" << StringUtils::URLEncode(m_defaultVersionId.c_str()) << "&";
  }
  if(m_attachmentCountHasBeenSet)
  {
      oStream << location << index << locationValue << ".AttachmentCount=" << m_attachmentCount << "&";
  }
  if(m_isAttachableHasBeenSet)
  {
      oStream << location << index << locationValue << ".IsAttachable=" << m_isAttachable << "&";
  }
  if(m_descriptionHasBeenSet)
  {
      oStream << location << index << locationValue << ".Description=" << StringUtils::URLEncode(m_description.c_str()) << "&";
  }
  if(m_createDateHasBeenSet)
  {
      oStream << location << index << locationValue << ".CreateDate=" << m_createDate << "&";
  }
  if(m_updateDateHasBeenSet)
  {
      oStream << location << index << locationValue << ".UpdateDate=" << m_updateDate << "&";
  }
  if(m_policyVersionListHasBeenSet)
  {
      for(auto& item : m_policyVersionList)
      {
        Aws::StringStream policyVersionListSs;
        policyVersionListSs << location << index << locationValue << ".PolicyVersionList";
        item.OutputToStream(oStream, policyVersionListSs.str().c_str());
      }
  }
}

void ManagedPolicyDetail::OutputToStream(Aws::OStream& oStream, const char* location) const
{
  if(m_policyNameHasBeenSet)
  {
      oStream << location << ".PolicyName=" << StringUtils::URLEncode(m_policyName.c_str()) << "&";
  }
  if(m_policyIdHasBeenSet)
  {
      oStream << location << ".PolicyId=" << StringUtils::URLEncode(m_policyId.c_str()) << "&";
  }
  if(m_arnHasBeenSet)
  {
      oStream << location << ".Arn=" << StringUtils::URLEncode(m_arn.c_str()) << "&";
  }
  if(m_pathHasBeenSet)
  {
      oStream << location << ".Path=" << StringUtils::URLEncode(m_path.c_str()) << "&";
  }
  if(m_defaultVersionIdHasBeenSet)
  {
      oStream << location << ".DefaultVersionId=" << StringUtils::URLEncode(m_defaultVersionId.c_str()) << "&";
  }
  if(m_attachmentCountHasBeenSet)
  {
      oStream << location << ".AttachmentCount=" << m_attachmentCount << "&";
  }
  if(m_isAttachableHasBeenSet)
  {
      oStream << location << ".IsAttachable=" << m_isAttachable << "&";
  }
  if(m_descriptionHasBeenSet)
  {
      oStream << location << ".Description=" << StringUtils::URLEncode(m_description.c_str()) << "&";
  }
  if(m_createDateHasBeenSet)
  {
      oStream << location << ".CreateDate=" << m_createDate << "&";
  }
  if(m_updateDateHasBeenSet)
  {
      oStream << location << ".UpdateDate=" << m_updateDate << "&";
  }
  if(m_policyVersionListHasBeenSet)
  {
      for(auto& item : m_policyVersionList)
      {
        Aws::String locationAndListMember(location);
        locationAndListMember += ".PolicyVersionList";
        item.OutputToStream(oStream, locationAndListMember.c_str());
      }
  }
}


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<meta http-equiv="Content-Type" content="text/html" charset="UTF-8">
<title>Uses of Package com.hazelcast.util.executor (Hazelcast Root 3.3.3 API)</title>
<meta name="date" content="2014-11-12">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">

JavaScript is disabled on your browser.

Overview

Package

Class

Use

Tree

Deprecated

Index

Help

Prev

Next

Frames

No Frames

All Classes

Uses of Package
com.hazelcast.util.executor

Packages that use com.hazelcast.util.executor

Package
Description

com.hazelcast.client.util

This package contains some utility classes and the base implementations of the
 loadbalancer implementations

com.hazelcast.jmx

Contains Hazelcast management bean classes.

com.hazelcast.management

Contains classes to provide data/operation interface for Management Center.

com.hazelcast.spi

Provides interfaces/classes for Hazelcast SPI.

com.hazelcast.spi.impl

Contains implementations for Hazelcast SPI.

com.hazelcast.util.executor

This package contains classes related to Util.Executor

Classes in com.hazelcast.util.executor used by com.hazelcast.client.util

Class and Description

DelegatingFuture

Classes in com.hazelcast.util.executor used by com.hazelcast.jmx

Class and Description

ManagedExecutorService

Classes in com.hazelcast.util.executor used by com.hazelcast.management

Class and Description

ManagedExecutorService

Classes in com.hazelcast.util.executor used by com.hazelcast.spi

Class and Description

ExecutorType

ManagedExecutorService

Classes in com.hazelcast.util.executor used by com.hazelcast.spi.impl

Class and Description

ExecutorType

ManagedExecutorService

Classes in com.hazelcast.util.executor used by com.hazelcast.util.executor

Class and Description

AbstractExecutorThreadFactory

ExecutorType

ManagedExecutorService

Overview

Package

Class

Use

Tree

Deprecated

Index

Help

Prev

Next

Frames

No Frames

All Classes

Copyright © 2014 Hazelcast, Inc.. All Rights Reserved.


text:
package org.alpha.mongo.thread.task;

public enum Functions {
	UPLOAD, DOWNLOAD
}