@@ -23,7 +23,7 @@ impl FeoxStore {
2323 ///
2424 /// # Returns
2525 ///
26- /// Returns `Ok(()) ` if successful .
26+ /// Returns `Ok(true)` if a new key was inserted, `Ok(false) ` if an existing key was updated .
2727 ///
2828 /// # Errors
2929 ///
@@ -47,7 +47,7 @@ impl FeoxStore {
4747 ///
4848 /// * Memory mode: ~600ns
4949 /// * Persistent mode: ~800ns (buffered write)
50- pub fn insert ( & self , key : & [ u8 ] , value : & [ u8 ] ) -> Result < ( ) > {
50+ pub fn insert ( & self , key : & [ u8 ] , value : & [ u8 ] ) -> Result < bool > {
5151 self . insert_with_timestamp ( key, value, None )
5252 }
5353
@@ -70,7 +70,7 @@ impl FeoxStore {
7070 key : & [ u8 ] ,
7171 value : & [ u8 ] ,
7272 timestamp : Option < u64 > ,
73- ) -> Result < ( ) > {
73+ ) -> Result < bool > {
7474 self . insert_with_timestamp_and_ttl_internal ( key, value, timestamp, 0 )
7575 }
7676
@@ -90,7 +90,7 @@ impl FeoxStore {
9090 ///
9191 /// # Returns
9292 ///
93- /// Returns `Ok(()) ` if successful .
93+ /// Returns `Ok(true)` if a new key was inserted, `Ok(false) ` if an existing key was updated .
9494 ///
9595 /// # Errors
9696 ///
@@ -116,7 +116,7 @@ impl FeoxStore {
116116 ///
117117 /// * Memory mode: ~600ns (avoids value copy)
118118 /// * Persistent mode: ~800ns (buffered write, avoids value copy)
119- pub fn insert_bytes ( & self , key : & [ u8 ] , value : Bytes ) -> Result < ( ) > {
119+ pub fn insert_bytes ( & self , key : & [ u8 ] , value : Bytes ) -> Result < bool > {
120120 self . insert_bytes_with_timestamp ( key, value, None )
121121 }
122122
@@ -139,7 +139,7 @@ impl FeoxStore {
139139 key : & [ u8 ] ,
140140 value : Bytes ,
141141 timestamp : Option < u64 > ,
142- ) -> Result < ( ) > {
142+ ) -> Result < bool > {
143143 self . insert_bytes_with_timestamp_and_ttl_internal ( key, value, timestamp, 0 )
144144 }
145145
@@ -149,7 +149,7 @@ impl FeoxStore {
149149 value : & [ u8 ] ,
150150 timestamp : Option < u64 > ,
151151 ttl_expiry : u64 ,
152- ) -> Result < ( ) > {
152+ ) -> Result < bool > {
153153 let start = std:: time:: Instant :: now ( ) ;
154154 let timestamp = match timestamp {
155155 Some ( 0 ) | None => self . get_timestamp ( ) ,
@@ -217,7 +217,7 @@ impl FeoxStore {
217217 }
218218 }
219219
220- Ok ( ( ) )
220+ Ok ( !is_update )
221221 }
222222
223223 /// Internal method to insert a Bytes value with timestamp and TTL (zero-copy)
@@ -227,7 +227,7 @@ impl FeoxStore {
227227 value : Bytes ,
228228 timestamp : Option < u64 > ,
229229 ttl_seconds : u64 ,
230- ) -> Result < ( ) > {
230+ ) -> Result < bool > {
231231 let start = std:: time:: Instant :: now ( ) ;
232232 // Get timestamp before any operations
233233 let timestamp = match timestamp {
@@ -242,6 +242,7 @@ impl FeoxStore {
242242 }
243243
244244 // Check for existing record
245+ let is_update = self . hash_table . contains ( key) ;
245246 let existing_record = self . hash_table . read ( key, |_, v| v. clone ( ) ) ;
246247 if let Some ( existing_record) = existing_record {
247248 let existing_ts = existing_record. timestamp ;
@@ -300,7 +301,7 @@ impl FeoxStore {
300301 . memory_usage
301302 . fetch_add ( new_size, Ordering :: AcqRel ) ;
302303 self . stats
303- . record_insert ( start. elapsed ( ) . as_nanos ( ) as u64 , false ) ;
304+ . record_insert ( start. elapsed ( ) . as_nanos ( ) as u64 , is_update ) ;
304305
305306 // Only do persistence if not in memory-only mode
306307 if !self . memory_only {
@@ -312,7 +313,7 @@ impl FeoxStore {
312313 }
313314 }
314315
315- Ok ( ( ) )
316+ Ok ( !is_update )
316317 }
317318
318319 /// Retrieve a value by key.
0 commit comments