<commit_before>/******************************************************************************
 *  Copyright (c) 2014 <NAME> 
 *  Distributed under the MIT license 
 *  (See accompanying file LICENSE or copy at http://opensource.org/licenses/MIT)
 *  
 *  Project: Database
 *  Filename: db_tablemanager.h 
 *  Version: 1.0
 *  Author: <NAME>
 *  E-mail: <EMAIL>
 *  Date: Oct. 23, 2014
 *  Time: 08:47:20
 *  Description: read and write table page, manage table header
 *****************************************************************************/
#ifndef DB_TABLEMANAGER_H_
#define DB_TABLEMANAGER_H_

#include <cassert>
#include <string>
#include <array>
#include "db_common.h"
#include "db_file.h"
#include "db_fields.h"

class Database::DBTableManager {
private:
    static constexpr char DB_SUFFIX[] = ".tb";
    static constexpr char ALIGN = 0x00;
    // default page size, in Bytes
    static constexpr uint64 DEFAULT_PAGE_SIZE = 4096 * 1024;

    // header pages format constants
    static constexpr uint64 TABLE_NAME_LENGTH = 512;
    static constexpr uint64 FIELD_INFO_LENGTH = 256;
    static constexpr uint64 PAGE_HEADER_LENGTH = 24;
    static constexpr uint64 FIRST_FIELDS_INFO_PAGE = 2;
    static constexpr uint64 FIRST_RECORD_PAGE = 5;
    static constexpr uint64 FIRST_EMPTY_SLOT_PAGE = 3;
    static constexpr uint64 FIRST_EMPTY_PAGE_PAGE = 4;



public:
    DBTableManager(): _file(nullptr) { }
    ~DBTableManager() {
        // open table should be closed explicitly
        // but we will close it if not
        if (isopen()) {
        // ignore close fail
            _file->close();
            delete _file;
            _file = nullptr;
        }
    }

    // create a table 
    // assert _file == nullptr
    // i.e. no table have been opened
    // returns 0 if succeed, 1 otherwise
    // table won't be opened  after created
    bool create(const std::string& table_name,
                const DBFields& fields, 
                uint64 page_size = DEFAULT_PAGE_SIZE) {
        // there's already a table opened
        if (isopen()) return 1;
        <commit_msg>modify default page size from 4096KB to 4KB<commit_after>/******************************************************************************
 *  Copyright (c) 2014 <NAME> 
 *  Distributed under the MIT license 
 *  (See accompanying file LICENSE or copy at http://opensource.org/licenses/MIT)
 *  
 *  Project: Database
 *  Filename: db_tablemanager.h 
 *  Version: 1.0
 *  Author: <NAME>
 *  E-mail: <EMAIL>
 *  Date: Oct. 23, 2014
 *  Time: 08:47:20
 *  Description: read and write table page, manage table header
 *****************************************************************************/
#ifndef DB_TABLEMANAGER_H_
#define DB_TABLEMANAGER_H_

#include <cassert>
#include <string>
#include <array>
#include "db_common.h"
#include "db_file.h"
#include "db_fields.h"

class Database::DBTableManager {
private:
    static constexpr char DB_SUFFIX[] = ".tb";
    static constexpr char ALIGN = 0x00;
    // default page size, in Bytes
    static constexpr uint64 DEFAULT_PAGE_SIZE = 4 * 1024;

    // header pages format constants
    static constexpr uint64 TABLE_NAME_LENGTH = 512;
    static constexpr uint64 FIELD_INFO_LENGTH = 256;
    static constexpr uint64 PAGE_HEADER_LENGTH = 24;
    static constexpr uint64 FIRST_FIELDS_INFO_PAGE = 2;
    static constexpr uint64 FIRST_RECORD_PAGE = 5;
    static constexpr uint64 FIRST_EMPTY_SLOT_PAGE = 3;
    static constexpr uint64 FIRST_EMPTY_PAGE_PAGE = 4;

public:
    DBTableManager(): _file(nullptr) { }
    ~DBTableManager() {
        // open table should be closed explicitly
        // but we will close it if not
        if (isopen()) {
        // ignore close fail
            _file->close();
            delete _file;
            _file = nullptr;
        }
    }

    // create a table 
    // assert _file == nullptr
    // i.e. no table have been opened
    // returns 0 if succeed, 1 otherwise
    // table won't be opened  after created
    bool create(const std::string& table_name,
                const DBFields& fields, 
                uint64 page_size = DEFAULT_PAGE_SIZE) {
        // there's already a table opened
        if (isopen()) return 1;
        
{'fraction_non_alphanumeric': 0.15581340279422212, 'fraction_numerical': 0.02983660904570211, 'mean_word_length': 2.9402985074626864, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '621391', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1180, 'n_words': 391}