English 中文(简体)
Persistent Data Structure
  • 时间:2024-12-22

Persistent Data Structure


Previous Page Next Page  

A data structure is said to be persistent if it is capable to maintaining its previous updates as separate versions and each version can be accessed and updated accordingly. It makes the data structure immutable and thread safe. For example, String class object in Java is immutable. Whenever we make any change to string, JVM creates another string object, assigned it the new value and preserve the older value as old string object.

A persistent data structure is also called a functional data structure. Consider the following case −

Non-Persistent way

pubpc static Person updateAge(Person person, int age){
   person.setAge(age);
   return person;
}

Persistent way

pubpc static Person updateAge(Person pPerson, int age){
   Person person = new Person();
   person.setAge(age);
   return person;
}
Advertisements