using System;
using System.Collections.Generic;

namespace KitsuneCafe.System
{
    public class FComparer<T> : IComparer<T>
    {
        private readonly Func<T, T, int> comparer;

        public FComparer(Func<T, T, int> comparer)
        {
            this.comparer = comparer;
        }
        public static IComparer<T> Create(Func<T, T, int> comparer)
        {
            return new FComparer<T>(comparer);
        }

        public int Compare(T x, T y)
        {
            return comparer(x, y);
        }
    }

    public class FEqualityComparer<T> : IEqualityComparer<T>
    {
        private readonly Func<T, T, bool> comparer;

        public FEqualityComparer(Func<T, T, bool> comparer)
        {
            this.comparer = comparer;
        }

        public static IEqualityComparer<T> Create(Func<T, T, bool> comparer)
        {
            return new FEqualityComparer<T>(comparer);
        }

        public bool Equals(T a, T b)
        {
            return comparer(a, b);
        }

        public int GetHashCode(T obj)
        {
            return obj.GetHashCode();
        }
    }
}