AD
AdemCatamak/ReaderPoC
project implements a key-value store with two distinct strategies for handling case-insensitive key comparison
Key-Value Store Reader Implementation
Overview
This project implements a key-value store with two distinct strategies for handling case-insensitive key comparison in the Get method:
- Comparator-based Strategy: Uses a comparator interface to define custom comparison logic.
- Inheritance-based Strategy: Creates separate reader implementations, each with its own
Getmethod for specific comparison logic.
Solution Structure
1. Comparator-based Strategy
Located in comparisonStrategySolution, this approach defines a comparator interface for key comparison, enabling flexible comparison methods by passing different comparator implementations to the reader. Key components:
comparator.go: Defines the comparator interface and custom comparator functions.defaultReader.go: Implements a reader that accepts a comparator, allowing it to use various comparison strategies.
2. Inheritance-based Strategy
Found in inheritanceSolution, this solution involves creating multiple reader structs for different comparison types:
defaultReader.go: A reader with case-sensitiveGetbehavior.caseInsensitiveReader.go: ExtendsdefaultReaderto support case-insensitive key matching.
Usage
To use either approach, instantiate the appropriate reader or comparator, then call the Get method with the desired key.
-
Comparator-based Reader:
- Create a
defaultReaderwith a specific comparator. - Use the
Getmethod to retrieve values based on the provided comparison logic.
r := comparisonStrategySolution.NewReader() result := r.Get("hello") r := comparisonStrategySolution.NewReader().WithComparator(comparisonStrategySolution.NewCaseInsensitiveComparator()) result := r.Get("hello") - Create a
-
Inheritance-based Reader:
- Choose between
defaultReaderorcaseInsensitiveReaderfor the desired key sensitivity. - Call
Getto retrieve values, with comparison behavior defined by the reader type.
r := inheritanceSolution.NewReader() result := r.Get("hello") r := inheritanceSolution.NewCaseInsensitiveReader() result := r.Get("hello") - Choose between