<commit_before>/**
 * FollowLink.h
 *
 * Follow a binary link.
 *
 * Copyright (c) 2008 <NAME> <<EMAIL>>
 */
#include <stdio.h>

#include "Atom.h"
#include "Link.h"
#include "Foreach.h"
#include "TLB.h"

namespace opencog {

class FollowLink
{
	public:

		/**
		 * follow_binary_link -- follow an ordered, binary link.
		 *
		 * Look at the incoming set of this atom.
		 * Find the first link of type link_type,
		 * then follow this link to see where its going.
		 * Its asssumed that there is only one such link,
		 * and that its binary.
		 * Return a pointer to where the link is going.
		 */
		inline Atom * follow_binary_link(Atom *atom, Type ltype)
		{
			return follow_link(atom, ltype, 0, 1);
		}

		inline Atom * backtrack_binary_link(Atom *atom, Type ltype)
		{
			return follow_link(atom, ltype, 1, 0);
		}

		inline Atom * follow_link(Atom *atom, Type ltype, int from, int to)
		{
			// Look for incoming links that are of the given type.
			// Then grab the thing that they link to.
			link_type = ltype;
			from_atom = atom;
			position_from = from;
			position_to = to;
			Handle h = TLB::getHandle(atom);
			foreach_incoming_atom(h, &FollowLink::find_link_type, this);
			return to_atom;<commit_msg>fix uninitialized var leading to crash<commit_after>/**
 * FollowLink.h
 *
 * Follow a binary link.
 *
 * Copyright (c) 2008 <NAME> <<EMAIL>>
 */
#include <stdio.h>

#include "Atom.h"
#include "Link.h"
#include "Foreach.h"
#include "TLB.h"

namespace opencog {

class FollowLink
{
	public:

		/**
		 * follow_binary_link -- follow an ordered, binary link.
		 *
		 * Look at the incoming set of this atom.
		 * Find the first link of type link_type,
		 * then follow this link to see where its going.
		 * Its asssumed that there is only one such link,
		 * and that its binary.
		 * Return a pointer to where the link is going.
		 */
		inline Atom * follow_binary_link(Atom *atom, Type ltype)
		{
			return follow_link(atom, ltype, 0, 1);
		}

		inline Atom * backtrack_binary_link(Atom *atom, Type ltype)
		{
			return follow_link(atom, ltype, 1, 0);
		}

		inline Atom * follow_link(Atom *atom, Type ltype, int from, int to)
		{
			if (NULL == atom) return NULL;

			// Look for incoming links that are of the given type.
			// Then grab the thing that they link to.
			link_type = ltype;
			from_atom = atom;
			to_atom = NULL;
			position_from = from;
			position_to = to;
			Handle h = TLB::getHandle(atom);
			foreach_incoming_atom(h, &FollowLink::find_link_type, this);
			return to_atom;
{'fraction_non_alphanumeric': 0.10792512943050578, 'fraction_numerical': 0.006371963361210673, 'mean_word_length': 3.145214521452145, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3182481', 'n_tokens_mistral': 975, 'n_tokens_neox': 847, 'n_words': 299}