9 Persistent data structures

 

Standing on the shoulders of giants

Hidden listing
function KlipseLoadLib(url, symbol) {
  if (window[symbol]) {
    return;
  }
  var script = document.createElement('script');
  script.src = url;
  document.body.append(script);
}
KlipseLoadLib("https://cdnjs.cloudflare.com/ajax/libs/immutable/4.0.0/immutable.min.js", "Immutable");
class UserManagement {};
window.UserManagement = UserManagement;

This chapter covers

  • The internal details of persistent data structures
  • The time and memory efficiency of persistent data structures
  • Using persistent data structures in an application

In part 1, we illustrated how to manage the state of a system without mutating data, where immutability is maintained by constraining ourselves to manipulate the state only with immutable functions using structural sharing. In this chapter, we present a safer and more scalable way to preserve data immutability—representing data with so-called persistent data structures. Efficient implementations of persistent data structures exist for most programming languages via third-party libraries.

9.1 The need for persistent data structures

9.2 The efficiency of persistent data structures

9.3 Persistent data structures libraries

9.3.1 Persistent data structures in Java

9.3.2 Persistent data structures in JavaScript

9.4 Persistent data structures in action

9.4.1 Writing queries with persistent data structures

9.4.2 Writing mutations with persistent data structures

9.4.3 Serialization and deserialization

9.4.4 Structural diff

Summary