@@ -9,6 +9,53 @@ double vectorValueOrDefault(const std::vector<double>& values, const size_t inde
99 return index < values.size () ? values[index] : 0.0 ;
1010}
1111
12+ struct SemanticVersion {
13+ int major = 0 ;
14+ int minor = 0 ;
15+ int patch = 0 ;
16+ bool valid = false ;
17+ };
18+
19+ SemanticVersion parseVersion (const std::string& versionStr) {
20+ SemanticVersion version;
21+
22+ if (versionStr.empty ()) {
23+ return version;
24+ }
25+
26+ size_t pos = 0 ;
27+ size_t dotPos = versionStr.find (' .' );
28+
29+ try {
30+ // Parse major version
31+ if (dotPos == std::string::npos) {
32+ // Partial version with only major - not valid for strict semver
33+ return version;
34+ }
35+
36+ version.major = std::stoi (versionStr.substr (pos, dotPos - pos));
37+ pos = dotPos + 1 ;
38+
39+ // Parse minor version
40+ dotPos = versionStr.find (' .' , pos);
41+ if (dotPos == std::string::npos) {
42+ // Partial version with major.minor only - not valid for strict semver
43+ return version;
44+ }
45+
46+ version.minor = std::stoi (versionStr.substr (pos, dotPos - pos));
47+ pos = dotPos + 1 ;
48+
49+ // Parse patch version
50+ version.patch = std::stoi (versionStr.substr (pos));
51+ version.valid = true ;
52+ } catch (...) {
53+ version.valid = false ;
54+ }
55+
56+ return version;
57+ }
58+
1259} // namespace
1360
1461const std::vector<std::string>& FeatureSchemaV1::names () {
@@ -83,7 +130,33 @@ const std::vector<std::string>& FeatureSchemaV1::names() {
83130 return kNames ;
84131}
85132
86- bool FeatureSchemaV1::isCompatible (const std::string& version) { return version == kVersion ; }
133+ bool FeatureSchemaV1::isCompatible (const std::string& version) {
134+ const auto current = parseVersion (kVersion );
135+ const auto provided = parseVersion (version);
136+
137+ // Both versions must be valid
138+ if (!current.valid || !provided.valid ) {
139+ return false ;
140+ }
141+
142+ // Major version must match exactly (breaking changes)
143+ if (provided.major != current.major ) {
144+ return false ;
145+ }
146+
147+ // Minor version must be >= current (backward compatible)
148+ if (provided.minor < current.minor ) {
149+ return false ;
150+ }
151+
152+ // If minor version is greater, patch doesn't matter (newer compatible version)
153+ if (provided.minor > current.minor ) {
154+ return true ;
155+ }
156+
157+ // Minor versions match, so patch must be >= current
158+ return provided.patch >= current.patch ;
159+ }
87160
88161size_t FeatureSchemaV1::featureCount () { return names ().size (); }
89162
0 commit comments