<commit_before>﻿using System.Linq;
using System.Collections.Generic;
using System.Reflection;

namespace ExpressWalker
{
    public class PropertyGuard
    {
        private List<int> _path;

        public PropertyGuard()
        {
            _path = new List<int>();
        }

        private PropertyGuard(IEnumerable<int> path)
        {
            _path = new List<int>(path);
        }

        public void Next(PropertyInfo property)
        {
            if (property == null)
            {
                return;
            }

            var hash = GetHash(property.DeclaringType.FullName, property.Name);

            if (!IsRepeating(hash))
            {
                _path.Add(hash);
            }
        }

        private bool IsRepeating(int hash)
        {
            if (_path.Count < 1)
            {
                return _path.All(h => h != hash);
            }

            var reverseIndex = 1;

            while (reverseIndex < _path.Count / 2)
            {
                var currentIndex = _path.Count - reverseIndex;

                var doubleIndex = currentIndex * 2;

                if (hash == _path[currentIndex] && _path[currentIndex] == _path[doubleIndex])
                {
                    //[cnt-1, cnt-curr+1] == [cnt-curr-1, cnt-curr*2+1]
                      
                    //TODO: compare sequences. If are equal, exit and return true;
                }

                reverseIndex++;
            }

            return false;
        }

        public PropertyGuard Copy()
        {
            return new PropertyGuard(_path);
        }

        public int GetHash(string declaringType, string propertyName)
        {<commit_msg>pseudo code for solution for circular reference issue in TypeBuilder.Build()<commit_after>﻿using System.Linq;
using System.Collections.Generic;
using System.Reflection;

namespace ExpressWalker
{
    public class PropertyGuard
    {
        private List<int> _path;

        public PropertyGuard()
        {
            _path = new List<int>();
        }

        private PropertyGuard(IEnumerable<int> path)
        {
            _path = new List<int>(path);
        }

        public void Next(PropertyInfo property)
        {
            if (property == null)
            {
                return;
            }

            var hash = GetHash(property.DeclaringType.FullName, property.Name);

            if (!IsRepeating(hash))
            {
                _path.Add(hash);
            }
        }

        private bool IsRepeating(int hash)
        {
            if (_path.Count < 1)
            {
                return _path.All(h => h != hash);
            }

            var reverseIndex = 1;

            while (reverseIndex < _path.Count / 2)
            {
                var currentIndex = _path.Count - reverseIndex;

                var doubleIndex = currentIndex * 2;

                if (hash == _path[currentIndex] && _path[currentIndex] == _path[doubleIndex])
                {
                    //[cnt-1, cnt-curr+1] == [cnt-curr-1, cnt-curr*2+1]
                      
                    //TODO: compare sequences. If are equal, exit and return true;;
                }

                reverseIndex++;
            }

            return false;
        }

        public PropertyGuard Copy()
        {
            return new PropertyGuard(_path);
        }

        public int GetHash(string declaringType, string propertyName)
        {
{'fraction_non_alphanumeric': 0.09190751445086705, 'fraction_numerical': 0.005202312138728324, 'mean_word_length': 1.2784726793943384, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, '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': '7043344', 'n_tokens_mistral': 921, 'n_tokens_neox': 862, 'n_words': 209}