<commit_before>#ifndef __VERTEX_INDEX_READER__
#define __VERTEX_INDEX_READER__

/**
 * Copyright 2014 Open Connectome Project (http://openconnecto.me)
 * Written by <NAME> (<EMAIL>)
 *
 * This file is part of FlashGraph.
 *
 * 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.
 */

#include "FG_basic_types.h"
#include "io_interface.h"
#include "simple_KV_store.h"
#include "vertex.h"

class vertex_compute;
class directed_vertex_compute;

template<class ValueType>
class req_vertex_task
{
	vertex_id_t vid;
	vertex_compute *compute;
public:
	req_vertex_task() {
		vid = 0;
		compute = NULL;
	}

	req_vertex_task(vertex_id_t vid, vertex_compute &_compute) {
		this->vid = vid;
		this->compute = &_compute;
	}

	size_t get_idx() const {
		return vid + vertex_index::get_header_size() / sizeof(ValueType);
	}

	size_t get_num_entries() const {
		return 2;
	}

	void run(ValueType entries[], int num) {
		assert(num == 2);
#ifdef VERIFY_INDEX_READER
		extern vertex_index *test_vindex;
		directed_vertex_index *index = (directed_vertex_index *) test_vindex;
		assert(entries[0].get_off() == index->get_vertex(vid).get_off());
		if (vid < index->get_max_id())
			assert(entries[1].get_off() == index->get_vertex(vid + 1).get_off());
#endif
		in_mem_vertex_info info(vid, entries[0].get_off(),
				entries[1].get_off() - entries[0].get_off());
		compute->issue_io_request(info);
	}

	// Override the operator so it can be used in a priority queue.
	bool operator<(const req_vertex_task &task) const {
		return this->get_idx() > task.get_idx();
	}
};

class req_part_vertex_task
{
	directed_vertex_request req;
	directed_vertex_compute *compute;
public:
	req_part_vertex_task() {
		compute = NULL;
	}

	req_part_vertex_task(directed_vertex_request &req,
			directed_vertex_compute &_compute) {
		this->req = req;
		this->compute = &_compute;
	}

	size_t get_idx() const {
		return req.get_id()
			+ vertex_index::get_header_size() / sizeof(directed_vertex_entry);
	}

	size_t get_num_entries() const {
		return 2;
	}

	void run(directed_vertex_entry entries[], int num) {
		assert(num == 2);
#ifdef VERIFY_INDEX_READER
		extern vertex_index *test_vindex;
		directed_vertex_index *index = (directed_vertex_index *) test_vindex;
		assert(entries[0].get_off() == index->get_vertex(req.get_id()).get_off());
		if (req.get_id() < index->get_max_id())
			assert(entries[1].get_off() == index->get_vertex(req.get_id() + 1).get_off());
#endif
		in_mem_directed_vertex_info info(req.get_id(), entries[0].get_off(),
				entries[1].get_off() - entries[0].get_off(),
				entries[0].get_num_in_edges(), entries[0].get_num_out_edges());
		compute->issue_io_request(req, info);
	}
};

template<class ValueType>
class req_edge_task
{
	// The vertex whose edges the task requests.
	vertex_id_t vid;
	// The vertex compute of the vertex who issues the request.
	vertex_compute *compute;
public:
	req_edge_task() {
		vid = 0;
		compute = NULL;
	}

	req_edge_task(vertex_id_t vid, vertex_compute *compute) {
		this->vid = vid;
		this->compute = compute;
	}

	size_t get_idx() const {
		return vid + vertex_index::get_header_size() / sizeof(ValueType);
	}

	size_t get_num_entries() const {
		return 2;
	}

	void run(ValueType entries[], int num) {
		assert(num == 2);
#ifdef VERIFY_INDEX_READER
		extern vertex_index *test_vindex;
		directed_vertex_index *index = (directed_vertex_index *) test_vindex;
		assert(entries[0].get_off() == index->get_vertex(vid).get_off());
		if (vid < index->get_max_id())
			assert(entries[1].get_off() == index->get_vertex(vid + 1).get_off());
#endif
		compute->run_on_vertex_size(vid,
				entries[1].get_off() - entries[0].get_off());
	}

	// Override the operator so it can be used in a priority queue.
	bool operator<(const req_edge_task &task) const {
		return this->get_idx() > task.get_idx();
	}
};<commit_msg>[Graph]: fix a bug in testing vertex_index_reader.<commit_after>#ifndef __VERTEX_INDEX_READER__
#define __VERTEX_INDEX_READER__

/**
 * Copyright 2014 Open Connectome Project (http://openconnecto.me)
 * Written by <NAME> (<EMAIL>)
 *
 * This file is part of FlashGraph.
 *
 * 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.
 */

#include "FG_basic_types.h"
#include "io_interface.h"
#include "simple_KV_store.h"
#include "vertex.h"

class vertex_compute;
class directed_vertex_compute;

template<class ValueType>
class req_vertex_task
{
	vertex_id_t vid;
	vertex_compute *compute;
public:
	req_vertex_task() {
		vid = 0;
		compute = NULL;
	}

	req_vertex_task(vertex_id_t vid, vertex_compute &_compute) {
		this->vid = vid;
		this->compute = &_compute;
	}

	size_t get_idx() const {
		return vid + vertex_index::get_header_size() / sizeof(ValueType);
	}

	size_t get_num_entries() const {
		return 2;
	}

	void run(ValueType entries[], int num) {
		assert(num == 2);
#ifdef VERIFY_INDEX_READER
		extern vertex_index *test_vindex;
		vertex_index_temp<ValueType> *index = (vertex_index_temp<ValueType> *) test_vindex;
		assert(entries[0].get_off() == index->get_vertex(vid).get_off());
		if (vid < index->get_max_id())
			assert(entries[1].get_off() == index->get_vertex(vid + 1).get_off());
#endif
		in_mem_vertex_info info(vid, entries[0].get_off(),
				entries[1].get_off() - entries[0].get_off());
		compute->issue_io_request(info);
	}

	// Override the operator so it can be used in a priority queue.
	bool operator<(const req_vertex_task &task) const {
		return this->get_idx() > task.get_idx();
	}
};

class req_part_vertex_task
{
	directed_vertex_request req;
	directed_vertex_compute *compute;
public:
	req_part_vertex_task() {
		compute = NULL;
	}

	req_part_vertex_task(directed_vertex_request &req,
			directed_vertex_compute &_compute) {
		this->req = req;
		this->compute = &_compute;
	}

	size_t get_idx() const {
		return req.get_id()
			+ vertex_index::get_header_size() / sizeof(directed_vertex_entry);
	}

	size_t get_num_entries() const {
		return 2;
	}

	void run(directed_vertex_entry entries[], int num) {
		assert(num == 2);
#ifdef VERIFY_INDEX_READER
		extern vertex_index *test_vindex;
		directed_vertex_index *index = (directed_vertex_index *) test_vindex;
		assert(entries[0].get_off() == index->get_vertex(req.get_id()).get_off());
		if (req.get_id() < index->get_max_id())
			assert(entries[1].get_off() == index->get_vertex(req.get_id() + 1).get_off());
#endif
		in_mem_directed_vertex_info info(req.get_id(), entries[0].get_off(),
				entries[1].get_off() - entries[0].get_off(),
				entries[0].get_num_in_edges(), entries[0].get_num_out_edges());
		compute->issue_io_request(req, info);
	}
};

template<class ValueType>
class req_edge_task
{
	// The vertex whose edges the task requests.
	vertex_id_t vid;
	// The vertex compute of the vertex who issues the request.
	vertex_compute *compute;
public:
	req_edge_task() {
		vid = 0;
		compute = NULL;
	}

	req_edge_task(vertex_id_t vid, vertex_compute *compute) {
		this->vid = vid;
		this->compute = compute;
	}

	size_t get_idx() const {
		return vid + vertex_index::get_header_size() / sizeof(ValueType);
	}

	size_t get_num_entries() const {
		return 2;
	}

	void run(ValueType entries[], int num) {
		assert(num == 2);
#ifdef VERIFY_INDEX_READER
		extern vertex_index *test_vindex;
		vertex_index_temp<ValueType> *index = (vertex_index_temp<ValueType> *) test_vindex;
		assert(entries[0].get_off() == index->get_vertex(vid).get_off());
		if (vid < index->get_max_id())
			assert(entries[1].get_off() == index->get_vertex(vid + 1).get_off());
#endif
		compute->run_on_vertex_size(vid,
				entries[1].get_off() - entries[0].get_off());
	}

	// Override the operator so it can be used in a priority queue.
	bool operator<(const req_edge_task &task) const {
		return this->get_idx() > task.get_idx();
	}
};
{'fraction_non_alphanumeric': 0.12943201376936317, 'fraction_numerical': 0.008032128514056224, 'mean_word_length': 4.818424566088117, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1987484', 'n_tokens_mistral': 3229, 'n_tokens_neox': 3017, 'n_words': 722}