<commit_before>/*****************************************************
 * Created by Julian on 8/6/15.
 *      /^\    /^\
 *     {  O}  {  O}
 *      \ /    \ /
 *      //     //       _------_
 *     //     //     ./~        ~-_
 *    / ~----~/     /              \
 *  /         :   ./       _---_    ~-
 * |  \________) :       /~     ~\   |
 * |        /    |      |  :~~\  |   |
 * |       |     |      |  \___-~    |
 * |        \ __/`\______\.        ./
 *  \                     ~-______-~\.
 *  .|                                ~-_
 * /_____________________________________~~____
 *
*****************************************************/

#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#include "FSAllocator.h"

static size_t s_blockPointSize = sizeof(FSAllocator::_FSBlock *);
static size_t s_blockArrayPointSize = sizeof(FSAllocator::_FSBlockArray *);

#pragma mark - implement FSAllocator::_FSBlock

FSAllocator::_FSBlock::_FSBlock(size_t size)
:_block(NULL)
,_size(size)
,_index(0)
{
    if (_size > 0) {
        void *block = malloc(_size + FSALLOCATOR_PACK_SIZE);
        _block = (void *)((uintptr_t)block + FSALLOCATOR_PACK_SIZE);
        _FSBlock **address = (_FSBlock **)block;
        *address = this;
    }
}

FSAllocator::_FSBlock::~_FSBlock(void) {
    if (_block) {
        void *block = (void *)((uintptr_t)_block - FSALLOCATOR_PACK_SIZE);
        free(block);
    }
}

#pragma mark - implement FSAllocator::_FSBlockArray

FSAllocator::_FSBlockArray::_FSBlockArray(void)
:_length(FSALLOCATOR_DEFAULT_ARRAY_LENGTH)
,_count(0)
{
    _blocks = (_FSBlock **)calloc(_length, s_blockPointSize);
}

FSAllocator::_FSBlockArray::~_FSBlockArray(void) {
    if (_blocks) {
        free(_blocks);
    }
}

void FSAllocator::_FSBlockArray::enlargeBlockArray(void) {
    _length <<= 1;
    _blocks = (_FSBlock **)realloc(_blocks, _length * s_blockPointSize);
}

void FSAllocator::_FSBlockArray::addBlock(_FSBlock *block) {
    if (block) {
        if (_count == _length) {
            enlargeBlockArray();
        }
        block->setIndex(_count);
        _blocks[_count ++] = block;
    }
}
FSAllocator::_FSBlock * FSAllocator::_FSBlockArray::removeBlock(void) {
    _FSBlock *block = NULL;
    if (_count > 0) {
        block = _blocks[-- _count];
        _blocks[_count] = 0;
    }
    return block;
}
FSAllocator::_FSBlock * FSAllocator::_FSBlockArray::removeBlock(unsigned long index) {
    _FSBlock *block = NULL;
    if (index < _count) {
        _FSBlock *tail = _blocks[-- _count];
        _blocks[_count] = 0;
        block = _blocks[index];
        _blocks[index] = tail;
        tail->setIndex(index);
    }<commit_msg>Add some blank between functions<commit_after>/*****************************************************
 * Created by Julian on 8/6/15.
 *      /^\    /^\
 *     {  O}  {  O}
 *      \ /    \ /
 *      //     //       _------_
 *     //     //     ./~        ~-_
 *    / ~----~/     /              \
 *  /         :   ./       _---_    ~-
 * |  \________) :       /~     ~\   |
 * |        /    |      |  :~~\  |   |
 * |       |     |      |  \___-~    |
 * |        \ __/`\______\.        ./
 *  \                     ~-______-~\.
 *  .|                                ~-_
 * /_____________________________________~~____
 *
*****************************************************/

#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#include "FSAllocator.h"

static size_t s_blockPointSize = sizeof(FSAllocator::_FSBlock *);
static size_t s_blockArrayPointSize = sizeof(FSAllocator::_FSBlockArray *);

#pragma mark - implement FSAllocator::_FSBlock

FSAllocator::_FSBlock::_FSBlock(size_t size)
:_block(NULL)
,_size(size)
,_index(0)
{
    if (_size > 0) {
        void *block = malloc(_size + FSALLOCATOR_PACK_SIZE);
        _block = (void *)((uintptr_t)block + FSALLOCATOR_PACK_SIZE);
        _FSBlock **address = (_FSBlock **)block;
        *address = this;
    }
}

FSAllocator::_FSBlock::~_FSBlock(void) {
    if (_block) {
        void *block = (void *)((uintptr_t)_block - FSALLOCATOR_PACK_SIZE);
        free(block);
    }
}

#pragma mark - implement FSAllocator::_FSBlockArray

FSAllocator::_FSBlockArray::_FSBlockArray(void)
:_length(FSALLOCATOR_DEFAULT_ARRAY_LENGTH)
,_count(0)
{
    _blocks = (_FSBlock **)calloc(_length, s_blockPointSize);
}

FSAllocator::_FSBlockArray::~_FSBlockArray(void) {
    if (_blocks) {
        free(_blocks);
    }
}

void FSAllocator::_FSBlockArray::enlargeBlockArray(void) {
    _length <<= 1;
    _blocks = (_FSBlock **)realloc(_blocks, _length * s_blockPointSize);
}

void FSAllocator::_FSBlockArray::addBlock(_FSBlock *block) {
    if (block) {
        if (_count == _length) {
            enlargeBlockArray();
        }
        block->setIndex(_count);
        _blocks[_count ++] = block;
    }
}

FSAllocator::_FSBlock * FSAllocator::_FSBlockArray::removeBlock(void) {
    _FSBlock *block = NULL;
    if (_count > 0) {
        block = _blocks[-- _count];
        _blocks[_count] = 0;
    }
    return block;
}

FSAllocator::_FSBlock * FSAllocator::_FSBlockArray::removeBlock(unsigned long index) {
    _FSBlock *block = NULL;
    if (index < _count) {
        _FSBlock *tail = _blocks[-- _count];
        _blocks[_count] = 0;
        block = _blocks[index];
        _blocks[index] = tail;
        tail->setIndex(index);
    }
{'fraction_non_alphanumeric': 0.1921429901321914, 'fraction_numerical': 0.0040960714950660955, 'mean_word_length': 2.281612706169823, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7349723', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1793, 'n_words': 270}