<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Posts on Ivan Yurchenko</title>
    <link>https://ivanyu.me/posts/</link>
    <description>Recent content in Posts on Ivan Yurchenko</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Sun, 04 Jan 2026 07:02:00 +0100</lastBuildDate>
    <atom:link href="https://ivanyu.me/posts/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Embedding JVM in Rust</title>
      <link>https://ivanyu.me/blog/2026/01/04/embedding-jvm-in-rust/</link>
      <pubDate>Sun, 04 Jan 2026 07:02:00 +0100</pubDate>
      <guid>https://ivanyu.me/blog/2026/01/04/embedding-jvm-in-rust/</guid>
      <description>&lt;p&gt;Java ecosystem is rich and mature. I won&amp;rsquo;t be surprised if some application may need to call a piece of Java code. There are several options to do this, starting from the basic multi-processing. In this short post, I want to tell about embedding Java virtual machine (JVM) directly into Rust programs with the &lt;a href=&#34;https://crates.io/crates/jni&#34;&gt;&lt;code&gt;jni&lt;/code&gt;&lt;/a&gt; crate.&lt;/p&gt;&#xA;&lt;div style=&#34;background: seashell; padding: 1em; margin-bottom: 1em;&#34;&gt;&#xD;&#xA;&lt;p style=&#34;margin-bottom: 0.7em; font-weight: bold;&#34;&gt;In this post:&lt;/p&gt;&#xD;&#xA;&lt;ol style=&#34;margin-bottom: 0.7em;&#34;&gt;&#xD;&#xA;&#xA;&lt;li&gt;Embedding JVM into a Rust application.&#xA;&lt;li&gt;Calling Java code from Rust and Rust code from Java.&#xA;&#xD;&#xA;&lt;/ol&gt;&#xD;&#xA;&lt;/div&gt;&#xD;&#xA;&#xA;&lt;p&gt;The post assumes you&amp;rsquo;re familiar with Java and Rust. You can find the code from this post in &lt;a href=&#34;https://github.com/ivanyu/rust-jni-example/&#34;&gt;this repository on Github&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Proptest: property testing in Rust</title>
      <link>https://ivanyu.me/blog/2024/09/22/proptest-property-testing-in-rust/</link>
      <pubDate>Sun, 22 Sep 2024 17:35:12 +0300</pubDate>
      <guid>https://ivanyu.me/blog/2024/09/22/proptest-property-testing-in-rust/</guid>
      <description>&lt;p&gt;You probably heard about &lt;dfn&gt;property testing&lt;/dfn&gt; (AKA &lt;dfn&gt;property-based testing&lt;/dfn&gt;), a testing technique where test inputs are randomly generated in great quantity and particular desired properties of the code under test are checked. It&amp;rsquo;s very practical and I&amp;rsquo;m a big proponent of using it where it makes sense.&lt;/p&gt;&#xA;&lt;p&gt;In this post, I will tell you how I used property testing with the &lt;a href=&#34;https://crates.io/crates/proptest&#34;&gt;Proptest&lt;/a&gt; library in Rust to ensure the correctness of a bunch of generated serialization/deserialization code for the &lt;a href=&#34;https://kafka.apache.org/&#34;&gt;Apache Kafka&lt;/a&gt; protocol.&lt;/p&gt;&#xA;&lt;div style=&#34;background: seashell; padding: 1em; margin-bottom: 1em;&#34;&gt;&#xD;&#xA;&lt;p style=&#34;margin-bottom: 0.7em; font-weight: bold;&#34;&gt;In this post:&lt;/p&gt;&#xD;&#xA;&lt;ol style=&#34;margin-bottom: 0.7em;&#34;&gt;&#xD;&#xA;&#xA;&lt;li&gt;A real-life example of using property testing in Rust with Proptest.&#xA;&lt;li&gt;A step-by-step explanation.&#xA;&#xD;&#xA;&lt;/ol&gt;&#xD;&#xA;&lt;/div&gt;&#xD;&#xA;&#xA;&lt;p&gt;The post assumes you&amp;rsquo;re familiar with Rust. However, to follow it you don&amp;rsquo;t need any knowledge about Kafka or its protocol. I will explain the problem I was working on briefly, but will not go into much detail.&lt;/p&gt;&#xA;&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://kafka.apache.org/&#34;&gt;Apache Kafka&lt;/a&gt; has a sizeable custom binary protocol that is versioned, with various data types, optional fields, etc. Unfortunately, it doesn&amp;rsquo;t use a well-known serialization format like Protobuf. The protocol message schema is &lt;a href=&#34;https://github.com/ivanyu/kafka-protocol/tree/7879f1c01311912be5a055045111f1a628c47c60/clients/src/main/resources/common/message&#34;&gt;described in JSON&lt;/a&gt;. The actual Java code that does serialization and deserialization is generated from this description&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;&#xA;&lt;p&gt;I created a library &lt;a href=&#34;https://github.com/ivanyu/kafka_wire_protocol&#34;&gt;kafka_wire_protocol&lt;/a&gt;. It&amp;rsquo;s a generated de-/serialization code for the Kafka protocol, but for Rust (and in the future, for Go). The correctness of the generated code is paramount. I applied many testing techniques to it: quick unit tests, integration tests against a real Kafka instance, fuzzying. And also &lt;code&gt;kafka_wire_protocol&lt;/code&gt; is a good example of software that can benefit from property testing. About this is going to be this post.&lt;/p&gt;&#xA;&lt;p&gt;You don&amp;rsquo;t need to familiarize yourself with &lt;code&gt;kafka_wire_protocol&lt;/code&gt; to understand what will be discussed. I will give examples from the code, but they will be self-contained. However, if you&amp;rsquo;re interested, feel free to check out this &lt;a href=&#34;https://github.com/ivanyu/kafka_wire_protocol&#34;&gt;repo&lt;/a&gt; and follow the instruction in README to run the code generator, compile, and run the tests.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Kafka protocol practical guide</title>
      <link>https://ivanyu.me/blog/2024/09/08/kafka-protocol-practical-guide/</link>
      <pubDate>Sun, 08 Sep 2024 11:24:35 +0300</pubDate>
      <guid>https://ivanyu.me/blog/2024/09/08/kafka-protocol-practical-guide/</guid>
      <description>&lt;p&gt;I worked with the &lt;a href=&#34;https://kafka.apache.org/&#34;&gt;Apache Kafka&lt;/a&gt; protocol on the low level quite a bit. It wasn&amp;rsquo;t easy to start doing this following the official guide only and I read the code a lot. With this post, I want to give you a head start by guiding you step by step from primitive values to meaningful requests.&lt;/p&gt;&#xA;&lt;div style=&#34;background: seashell; padding: 1em; margin-bottom: 1em;&#34;&gt;&#xD;&#xA;&lt;p style=&#34;margin-bottom: 0.7em; font-weight: bold;&#34;&gt;In this post:&lt;/p&gt;&#xD;&#xA;&lt;ol style=&#34;margin-bottom: 0.7em;&#34;&gt;&#xD;&#xA;&#xA;&lt;li&gt;Explore the Kafka protocol code and the protocol in action with Wireshark.&#xA;&lt;li&gt;Learn how to read and write primitive values.&#xA;&lt;li&gt;Combine primitives to perform meaningful requests.&#xA;&#xD;&#xA;&lt;/ol&gt;&#xD;&#xA;&lt;/div&gt;&#xD;&#xA;&#xA;&lt;p&gt;We will use Python as the programming language. However, the code will be zero-dependency and easily portable to the language of your choice.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Java agents, Javassist and Byte Buddy</title>
      <link>https://ivanyu.me/blog/2017/11/04/java-agents-javassist-and-byte-buddy/</link>
      <pubDate>Sat, 04 Nov 2017 16:57:00 +0300</pubDate>
      <guid>https://ivanyu.me/blog/2017/11/04/java-agents-javassist-and-byte-buddy/</guid>
      <description>&lt;p&gt;Java Virtual Machine (JVM) is a really great platform, mature, and well-established. Apart from lots of normal features used by all developers, there are some that are more low-level, designed to serve more &amp;ldquo;system&amp;rdquo; or &amp;ldquo;tooling&amp;rdquo; purposes. One example is &lt;code&gt;sun.misc.Unsafe&lt;/code&gt;, which gives e.g. low-level access to memory. Another such feature is &lt;strong&gt;agents&lt;/strong&gt;. Agents are the JVM mechanism that enables external code to integrate with a running JVM, including access to the bytecode before it’s loaded and executed.&lt;/p&gt;&#xA;&lt;div style=&#34;background: seashell; padding: 1em; margin-bottom: 1em;&#34;&gt;&#xD;&#xA;&lt;p style=&#34;margin-bottom: 0.7em; font-weight: bold;&#34;&gt;In this post:&lt;/p&gt;&#xD;&#xA;&lt;ol style=&#34;margin-bottom: 0.7em;&#34;&gt;&#xD;&#xA;&#xA;&lt;li&gt;The basics of Java agents and Instrumentation API.&#xA;&lt;li&gt;An example agent for metrics collection.&#xA;&lt;li&gt;Libraries for bytecode manipulation: Javassist and Byte Buddy.&#xA;&#xD;&#xA;&lt;/ol&gt;&#xD;&#xA;&lt;/div&gt;&#xD;&#xA;&#xA;&lt;p&gt;Agents were introduced in Java 1.5, but programming them is rarely a part of JVM programmer&amp;rsquo;s everyday job. However, having JVM code in production means a high probability of using some agents. I&amp;rsquo;d like to mention several widely used classes of them:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;JMX-HTTP bridges, e.g. &lt;a href=&#34;https://jolokia.org&#34;&gt;Jolokia&lt;/a&gt;, which gives access to JXM MBeans over HTTP (very useful for monitoring);&lt;/li&gt;&#xA;&lt;li&gt;profilers, e.g. &lt;a href=&#34;https://www.yourkit.com/&#34;&gt;YourKit&lt;/a&gt; or &lt;a href=&#34;https://www.ej-technologies.com/products/jprofiler/overview.html&#34;&gt;JProfiler&lt;/a&gt;;&lt;/li&gt;&#xA;&lt;li&gt;debuggers, namely &lt;a href=&#34;https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/introclientissues005.html&#34;&gt;Java Debug Wire Protocol (JDWP)&lt;/a&gt; agent;&lt;/li&gt;&#xA;&lt;li&gt;aspect-oriented programming toolkits, &lt;a href=&#34;http://www.eclipse.org/aspectj/&#34;&gt;AspectJ&lt;/a&gt; in particular;&lt;/li&gt;&#xA;&lt;li&gt;hot code reloading tools like &lt;a href=&#34;https://zeroturnaround.com/software/jrebel/&#34;&gt;JRebel&lt;/a&gt;, which are especially useful in Java EE environment.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;There are two types of agents in JVM: &lt;dfn&gt;Java agents&lt;/dfn&gt; and &lt;dfn&gt;native agents&lt;/dfn&gt;. Java agents are in JVM bytecode (i.e. written in one of JVM languages, most commonly in Java) packed in JARs and follow special code organisation convention so as JVM could use them. Native agents are different: they&amp;rsquo;re in native code (most commonly compiled from C++) packed in dynamic libraries, use &lt;a href=&#34;https://docs.oracle.com/javase/8/docs/technotes/guides/jvmti/index.html&#34;&gt;JVM Tool Interface&lt;/a&gt;, and operate on a more low level than Java agents. Particularly, they can affect the garbage collector, thread management, locking and synchronisation, etc. Profilers and debuggers use native agents.&lt;/p&gt;&#xA;&lt;p&gt;In this post, we&amp;rsquo;re focusing solely on Java agents.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Publishing JARs to Bintray with Maven and SBT</title>
      <link>https://ivanyu.me/blog/2017/08/11/publishing-jars-to-bintray-with-maven-and-sbt/</link>
      <pubDate>Fri, 11 Aug 2017 15:03:00 +0300</pubDate>
      <guid>https://ivanyu.me/blog/2017/08/11/publishing-jars-to-bintray-with-maven-and-sbt/</guid>
      <description>&lt;p&gt;&lt;strong&gt;Update 26.03.2023:&lt;/strong&gt; In February 2021, &lt;a href=&#34;https://ivanyu.me/blog/2017/08/11/publishing-jars-to-bintray-with-maven-and-sbt/&#34;&gt;Bintray was shut down&lt;/a&gt;. This post still may be useful from the point of view of artifact publishing in Maven and SBT.&lt;/p&gt;&#xA;&lt;p&gt;Many developers are interested in making their JVM artifacts (e.g. libraries) available for others. Probably, the simplest way to do this is to publish an artifact to &lt;a href=&#34;https://bintray.com/&#34;&gt;Bintray&lt;/a&gt;, which gives free hosting for publicly available artifacts. Also, some teams would like to have private repositories for their shared JARs. In this case, Bintray can help as well.&lt;/p&gt;&#xA;&lt;div style=&#34;background: seashell; padding: 1em; margin-bottom: 1em;&#34;&gt;&#xD;&#xA;&lt;p style=&#34;margin-bottom: 0.7em; font-weight: bold;&#34;&gt;In this post:&lt;/p&gt;&#xD;&#xA;&lt;ol style=&#34;margin-bottom: 0.7em;&#34;&gt;&#xD;&#xA;&#xA;&lt;li&gt;Setting up a Bintray repository.&lt;/li&gt;&#xA;&lt;li&gt;Publishing JARs of a Maven project to Bintray, including sources, Javadoc and tests.&lt;/li&gt;&#xA;&lt;li&gt;Publishing JARs of an SBT project to Bintray + &lt;code&gt;sbt-bintray&lt;/code&gt; plugin.&lt;/li&gt;&#xA;&#xD;&#xA;&lt;/ol&gt;&#xD;&#xA;&lt;/div&gt;&#xD;&#xA;&#xA;&lt;p&gt;All the code used in this project is available in &lt;a href=&#34;https://github.com/ivanyu/bintray-hello-world&#34;&gt;bintray-hello-world Github repository&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>About Akka Streams</title>
      <link>https://ivanyu.me/blog/2016/12/12/about-akka-streams/</link>
      <pubDate>Mon, 12 Dec 2016 00:53:00 +0300</pubDate>
      <guid>https://ivanyu.me/blog/2016/12/12/about-akka-streams/</guid>
      <description>&lt;p style=&#34;text-align: right; font-size:70%; font-style: italic; margin-right: 10px; margin-bottom: 0.5em;&#34;&gt;Excellent post about Akka Streams — &lt;a href=&#34;https://twitter.com/akkateam/status/808964690495860736&#34;&gt;Akka Team&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p style=&#34;text-align: right; font-size:70%; font-style: italic; margin-right: 10px; margin-bottom: 0.5em;&#34;&gt;Really nice introduction to #Akka Streams! FEEL THE POWER! ^^ — &lt;a href=&#34;https://twitter.com/viktorklang/status/808830738053222400&#34;&gt;Viktor Klang&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p style=&#34;text-align: right; font-size:70%; font-style: italic; margin-right: 10px; margin-bottom: 1.6em;&#34;&gt;A must-read on #Akka #Streams!!! — &lt;a href=&#34;https://twitter.com/EllanVannin_CA/status/809147713619169285&#34;&gt;Ellan Vannin CA&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;In many computer programs, the whole logic (or a vast part of it) is essentially step-by-step processing of data. Of course, this includes the situation when we iterate over the data and just execute the processing logic on every piece of it. However, there are a couple of complications here:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;the processing logic may be quite complex, with various aggregations, merging, routing, error recoveries, etc.;&lt;/li&gt;&#xA;&lt;li&gt;we might want to execute steps asynchronously, for instance, to take advantage of multi-processor machines or use I/O;&lt;/li&gt;&#xA;&lt;li&gt;asynchronous execution of data processing steps inherently involves buffering, queues, congestion, and other matter, which are really difficult to handle properly (please, read &lt;a href=&#34;http://ferd.ca/handling-overload.html&#34;&gt;&amp;ldquo;Handling Overload&amp;rdquo; by Fred Hébert&lt;/a&gt;).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Therefore, sometimes it is a good idea to express this logic on a high level using some kind of a framework, without a need to implement (possibly complex) mechanics of asynchronous pipeline processing. This was one of the rationales behind frameworks like &lt;a href=&#34;https://en.wikipedia.org/wiki/Apache_Camel&#34;&gt;Apache Camel&lt;/a&gt; or &lt;a href=&#34;https://en.wikipedia.org/wiki/Storm_(event_processor)&#34;&gt;Apache Storm&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Actor systems like &lt;a href=&#34;http://www.erlang.org&#34;&gt;Erlang&lt;/a&gt; or &lt;a href=&#34;http://akka.io/&#34;&gt;Akka&lt;/a&gt; are fairly good for building robust asynchronous data pipelines. However, they are quite low-level by themselves, so writing such pipelines might be tiresome. Newer versions of Akka include the possibility for doing pipeline processing on a quite high level, which is called Akka Streams. Akka Streams grows from &lt;a href=&#34;http://www.reactive-streams.org/&#34;&gt;Reactive Streams initiative&lt;/a&gt;. It implements a streaming interface on top of Akka actor system. In this post I would like to give a short introduction to this library.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Time-based (version 1) UUIDs ordering in PostgreSQL</title>
      <link>https://ivanyu.me/blog/2016/03/28/time-based-version-1-uuids-ordering-in-postgresql/</link>
      <pubDate>Mon, 28 Mar 2016 11:27:00 +0300</pubDate>
      <guid>https://ivanyu.me/blog/2016/03/28/time-based-version-1-uuids-ordering-in-postgresql/</guid>
      <description>&lt;h2 id=&#34;the-problem&#34;&gt;The problem&lt;/h2&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Universally_unique_identifier&#34;&gt;UUID&lt;/a&gt; standard has several versions. Version 4 is purely random numbers, version 1 relies on the identity of a machine and the timestamp with the counter, etc. Let&amp;rsquo;s consider version 1 UUIDs. They include timestamps with counters, so they naturally can be ordered by it. In other words, having two time-based UUIDs, I wanted to say if the first is lower, greater or equal to the second. No big deal, say, in Java: &lt;code&gt;u1.timestamp().compare(u2.timestamp())&lt;/code&gt;. But I wanted to do this in PostgreSQL, inside SQL query. Postgresql does have &lt;code&gt;uuid&lt;/code&gt; data type, but it provides no functions for comparing them by version 1 timestamps. That is why I decided to write such a function myself.&lt;/p&gt;&#xA;&lt;h2 id=&#34;version-1-uuid-structure&#34;&gt;Version 1 UUID structure&lt;/h2&gt;&#xA;&lt;p&gt;You can find the full UUID specification in &lt;a href=&#34;https://www.ietf.org/rfc/rfc4122.txt&#34;&gt;RFC 4122&lt;/a&gt;. Let&amp;rsquo;s consider here only the part of version 1 which we are interested in. UUIDs have length of 128 bits, i.e. 16 bytes, which have different meaning in different versions of the standard. Version 1 layout is shown on the picture:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;images/uuid_v1.png&#34; alt=&#34;UUID version 1 structure&#34;&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Type-safe query builders in Scala revisited: shapeless</title>
      <link>https://ivanyu.me/blog/2016/01/11/type-safe-query-builders-in-scala-revisited-shapeless/</link>
      <pubDate>Mon, 11 Jan 2016 19:15:10 +0300</pubDate>
      <guid>https://ivanyu.me/blog/2016/01/11/type-safe-query-builders-in-scala-revisited-shapeless/</guid>
      <description>&lt;p&gt;Not so long ago, I wrote &lt;a href=&#34;https://ivanyu.me/blog/2015/10/18/type-safe-query-builders-in-scala/&#34;&gt;a post about creating type-safe query builders in Scala from scratch&lt;/a&gt;. In it, I also suggested using &lt;a href=&#34;https://github.com/milessabin/shapeless&#34;&gt;shapeless&lt;/a&gt; library to do what was described. Now, I decided to write how it could be done. The code is in &lt;a href=&#34;https://github.com/ivanyu/scala-typed-queries&#34;&gt;this repository&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;h2 id=&#34;problem-reminder&#34;&gt;Problem reminder&lt;/h2&gt;&#xA;&lt;p&gt;Without going into much details, the problem was to provide a type-safe way to build queries (to an abstract database, for instance) with parameters of different types. Something like&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-scala&#34; data-lang=&#34;scala&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#008000;font-weight:bold&#34;&gt;val&lt;/span&gt; query &lt;span style=&#34;color:#008000;font-weight:bold&#34;&gt;=&lt;/span&gt; beginQuery&lt;span style=&#34;color:#666&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#666&#34;&gt;.&lt;/span&gt;addParameter&lt;span style=&#34;color:#666&#34;&gt;[&lt;/span&gt;&lt;span style=&#34;color:#b00040&#34;&gt;String&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt;](&lt;/span&gt;&lt;span style=&#34;color:#ba2121&#34;&gt;&amp;#34;param1&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#666&#34;&gt;.&lt;/span&gt;addParameter&lt;span style=&#34;color:#666&#34;&gt;[&lt;/span&gt;&lt;span style=&#34;color:#b00040&#34;&gt;Int&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt;](&lt;/span&gt;&lt;span style=&#34;color:#ba2121&#34;&gt;&amp;#34;param2&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#666&#34;&gt;.&lt;/span&gt;addParameter&lt;span style=&#34;color:#666&#34;&gt;[&lt;/span&gt;&lt;span style=&#34;color:#b00040&#34;&gt;Boolean&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt;](&lt;/span&gt;&lt;span style=&#34;color:#ba2121&#34;&gt;&amp;#34;param3&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#666&#34;&gt;.&lt;/span&gt;build&lt;span style=&#34;color:#666&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#408080;font-style:italic&#34;&gt;// Compile:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#408080;font-style:italic&#34;&gt;&lt;/span&gt;query&lt;span style=&#34;color:#666&#34;&gt;.&lt;/span&gt;execute&lt;span style=&#34;color:#666&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#ba2121&#34;&gt;&amp;#34;some string&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#666&#34;&gt;1&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#008000;font-weight:bold&#34;&gt;false&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#408080;font-style:italic&#34;&gt;// Won&amp;#39;t compile:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#408080;font-style:italic&#34;&gt;&lt;/span&gt;query&lt;span style=&#34;color:#666&#34;&gt;.&lt;/span&gt;execute&lt;span style=&#34;color:#666&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt;42&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#008000;font-weight:bold&#34;&gt;true&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#ba2121&#34;&gt;&amp;#34;another string&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    <item>
      <title>Type-safe query builders in Scala</title>
      <link>https://ivanyu.me/blog/2015/10/18/type-safe-query-builders-in-scala/</link>
      <pubDate>Sun, 18 Oct 2015 15:12:00 +0300</pubDate>
      <guid>https://ivanyu.me/blog/2015/10/18/type-safe-query-builders-in-scala/</guid>
      <description>&lt;p&gt;&lt;strong&gt;Update 11.01.2016:&lt;/strong&gt; &lt;a href=&#34;https://ivanyu.me/blog/2016/01/11/type-safe-query-builders-in-scala-revisited-shapeless/&#34;&gt;the next post about type-safe query builders using shapeless&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Recently, I was hacking on a Scala library for queries to Cassandra database, &lt;a href=&#34;https://github.com/websudos/phantom&#34;&gt;phantom&lt;/a&gt;. At the moment, it was not able to build prepared statements, which I needed, so I added this functionality. However, phantom developers also implemented prepared statements quickly :) Nevertheless, I decided to write this post about the core idea of my implementation.&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;&lt;strong&gt;Caution:&lt;/strong&gt; Don&amp;rsquo;t do this at home, use &lt;a href=&#34;https://github.com/milessabin/shapeless&#34;&gt;shapeless&lt;/a&gt; :)&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;My plan was to be able to prepare queries like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-scala&#34; data-lang=&#34;scala&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#008000;font-weight:bold&#34;&gt;val&lt;/span&gt; query &lt;span style=&#34;color:#008000;font-weight:bold&#34;&gt;=&lt;/span&gt; select&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#666&#34;&gt;.&lt;/span&gt;where&lt;span style=&#34;color:#666&#34;&gt;(&lt;/span&gt;typedParamPlaceholder1&lt;span style=&#34;color:#666&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#666&#34;&gt;.&lt;/span&gt;and&lt;span style=&#34;color:#666&#34;&gt;(&lt;/span&gt;typedParamPlaceholder2&lt;span style=&#34;color:#666&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#666&#34;&gt;.&lt;/span&gt;and&lt;span style=&#34;color:#666&#34;&gt;(&lt;/span&gt;typedParamPlaceholder3&lt;span style=&#34;color:#666&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#666&#34;&gt;.&lt;/span&gt;build&lt;span style=&#34;color:#666&#34;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;and after that to execute this query: &lt;code&gt;query.execute(&amp;quot;string&amp;quot;, 1, false)&lt;/code&gt;. Moreover, I wanted this execution to be type-safe, so it was not possible to execute something like &lt;code&gt;query.execute(1, &amp;quot;string&amp;quot;, 0)&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;I will abstract from phantom queries and will focus on the general idea. The code is in &lt;a href=&#34;https://github.com/ivanyu/scala-typed-queries&#34;&gt;this repository&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>The Bloom filter</title>
      <link>https://ivanyu.me/blog/2015/04/05/the-bloom-filter/</link>
      <pubDate>Sun, 05 Apr 2015 11:54:00 +0300</pubDate>
      <guid>https://ivanyu.me/blog/2015/04/05/the-bloom-filter/</guid>
      <description>&lt;p&gt;In many software engineering problems, we have a set and need to determine if some value belongs to this set. If the possible maximum set cardinality (size; maximum size = total count of elements we consider) is small, the solution is straightforward: just store the set explicitly (for instance, in form of a RB-tree), update it when necessary and check if the set contains elements that we are interested in. But what if maximum set cardinality is large or we need many such sets to operate simultaneously? Or if the set membership test is an expensive operation?&lt;/p&gt;&#xA;&lt;p&gt;Suppose we want to know if an element belongs to a set. We have decided that it is acceptable to get false positive answers (the answer is &lt;em&gt;&amp;ldquo;yes&amp;rdquo;&lt;/em&gt;, but the element is not actually in the set) with probability &lt;code&gt;p&lt;/code&gt; and not acceptable to get false negative (the answer is &lt;em&gt;&amp;ldquo;no&amp;rdquo;&lt;/em&gt;, but the element in actually in the set). The data structure that could help us in this situation is called the &lt;dfn&gt;Bloom filter&lt;/dfn&gt;.&lt;/p&gt;&#xA;&lt;p&gt;A &lt;a href=&#34;https://en.wikipedia.org/wiki/Bloom_filter&#34;&gt;Bloom filter&lt;/a&gt; (proposed by Burton Howard Bloom in 1970) is a bit array of &lt;code&gt;m&lt;/code&gt; bits (initially set to 0) and &lt;code&gt;k&lt;/code&gt; different hash functions. Each hash function maps a value into a single integer number.&lt;/p&gt;&#xA;&lt;p&gt;Look at this picture from Wikipedia:&lt;/p&gt;&#xA;&lt;p style=&#34;text-align: center;&#34;&gt;&lt;img src=&#34;https://upload.wikimedia.org/wikipedia/commons/a/ac/Bloom_filter.svg&#34; alt=&#34;Bloom filter&#34; width=&#34;649&#34; height=&#34;233&#34;&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Delayed message delivery in RabbitMQ</title>
      <link>https://ivanyu.me/blog/2015/02/16/delayed-message-delivery-in-rabbitmq/</link>
      <pubDate>Mon, 16 Feb 2015 11:32:00 +0300</pubDate>
      <guid>https://ivanyu.me/blog/2015/02/16/delayed-message-delivery-in-rabbitmq/</guid>
      <description>&lt;p&gt;&lt;strong&gt;UPD June 01, 2015:&lt;/strong&gt; there is &lt;a href=&#34;http://www.rabbitmq.com/blog/2015/04/16/scheduling-messages-with-rabbitmq/&#34;&gt;a plugin&lt;/a&gt; for this now.&lt;/p&gt;&#xA;&lt;p&gt;A lot of developers use &lt;a href=&#34;https://www.rabbitmq.com/&#34;&gt;RabbitMQ&lt;/a&gt; message broker. It is quite mature but still lacks for some features that one may need. One of them is delayed message delivery: there is no way to send a message that will be delivered after a specified delay (it&amp;rsquo;s a limitation of &lt;a href=&#34;https://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol&#34;&gt;AMQP protocol&lt;/a&gt;). Hopefully, there is a hack for this.&lt;/p&gt;&#xA;&lt;p style=&#34;text-align: center;&#34;&gt;&lt;img src=&#34;https://ivanyu.me/images/rabbitmq_logo_strap.png&#34; alt=&#34;RabbitMQ logo&#34; title=&#34;RabbitMQ logo&#34; /&gt;&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s start from &lt;a href=&#34;http://www.rabbitmq.com/dlx.html&#34;&gt;dead letters&lt;/a&gt;. A message can become &amp;ldquo;dead&amp;rdquo; by several reasons, such as rejection or TTL (time to live) expiration. RabbitMQ can deal with such messages by redirecting them to a particular exchange and routing key. We can use this ability to implement delayed delivery. We will create a special queue for holding delayed messages. This queue will not have any subscribers in order for messages to expire. After the expiration, messages will be passed to a destination exchange and routing key, just as planned.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Introduction to Akka</title>
      <link>https://ivanyu.me/blog/2015/01/27/introduction-to-akka/</link>
      <pubDate>Tue, 27 Jan 2015 01:27:00 +0300</pubDate>
      <guid>https://ivanyu.me/blog/2015/01/27/introduction-to-akka/</guid>
      <description>&lt;p&gt;&lt;strong&gt;Update 26.03.2023:&lt;/strong&gt; In September 2022, Lightbend changed the license of Akka from Apache 2.0 to the source-available &lt;a href=&#34;https://www.lightbend.com/akka/license&#34;&gt;Business Source License (BSL) 1.1&lt;/a&gt;. Akka was forked as &lt;a href=&#34;https://pekko.apache.org/&#34;&gt;Pekko&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;There are several models of concurrent computing, &lt;dfn&gt;the actor model&lt;/dfn&gt; is one of them. I am going to give a glimpse of this model and one of its implementation - &lt;a href=&#34;http://akka.io/&#34;&gt;Akka toolkit&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p style=&#34;text-align: center;&#34;&gt;&lt;img src=&#34;https://ivanyu.me/images/akka_logo.png&#34; alt=&#34;Akka logo&#34; title=&#34;Akka logo&#34; /&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;the-actor-model&#34;&gt;The actor model&lt;/h2&gt;&#xA;&lt;p&gt;In the actor model, actors are objects that have state and behavior and communicate to each other by message passing. This sounds like good old objects from OOP, but the crucial difference is that message passing is one-way and asynchronous: an actor sends a message to another actor and continues its work. In fact, actors are totally reactive, all theirs activity is happening as reaction to incoming messages, which are processed one by one. However, it is not a limitation because messages can be of any sort including scheduled messages (by timer) and network messages.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Value Classes in Scala</title>
      <link>https://ivanyu.me/blog/2014/12/14/value-classes-in-scala/</link>
      <pubDate>Sun, 14 Dec 2014 20:51:00 +0300</pubDate>
      <guid>https://ivanyu.me/blog/2014/12/14/value-classes-in-scala/</guid>
      <description>&lt;p&gt;Type systems and compile-time type checking are great things that can save you a couple of hours of debugging and also have documenting potential, could make the code more understandable. In my opinion, it&amp;rsquo;s wise to use them, and unfortunately, sometimes we don&amp;rsquo;t do this enough. Consider &lt;code&gt;Integer&lt;/code&gt;/&lt;code&gt;Int&lt;/code&gt;/&lt;code&gt;int&lt;/code&gt;. A counter could be &lt;code&gt;Integer&lt;/code&gt;, an entity identifier could be &lt;code&gt;Integer&lt;/code&gt;, an integer number in arithmetic expression could be &lt;code&gt;Integer&lt;/code&gt;. In most cases all this &lt;code&gt;Integer&lt;/code&gt;s have nothing to do with each other: in your domain it is a bad idea to compare them, do arithmetic operations on them, pass one instead of another as a function parameter etc.&lt;/p&gt;&#xA;&lt;p&gt;In one of my projects (in C#) there are a dozen of domain entities that have integer identifiers that are passed all over the code. After a couple of bugs connected with mixed up identifiers of different entities I&amp;rsquo;ve solved this problem by replacing plain integer numbers with &lt;code&gt;struct&lt;/code&gt;s (in C#, &lt;code&gt;struct&lt;/code&gt;s are value types used for representing lightweight objects such as &lt;code&gt;Point&lt;/code&gt; or &lt;code&gt;Color&lt;/code&gt;) like &lt;code&gt;Id&amp;lt;EntityName&amp;gt;T&lt;/code&gt; (&lt;code&gt;T&lt;/code&gt; is to distinct type from property names). The key idea was to introduce a new level of types to let the type checker intently look at the code instead of me. It&amp;rsquo;s worked: I&amp;rsquo;ve gotten rid of some old bugs in rarely used parts of code and hope new bugs of such a type won&amp;rsquo;t bother me in the future. (&lt;em&gt;Aside:&lt;/em&gt; I hope, this post will persuade you not only to consider using value classes but also to think about the role of types in code quality).&lt;/p&gt;</description>
    </item>
    <item>
      <title>Why I like Scala</title>
      <link>https://ivanyu.me/blog/2014/11/24/why-i-like-scala/</link>
      <pubDate>Mon, 24 Nov 2014 17:15:00 +0300</pubDate>
      <guid>https://ivanyu.me/blog/2014/11/24/why-i-like-scala/</guid>
      <description>&lt;p&gt;I am familiar (more or less) with a number of programming languages and have both emotional and rational thoughts of them. Scala is for certain in the group of languages I like. I have decided to summarize my judgments of Scala attractive parts in a blog post and here it is. Also, I have got some ideas of posts about Scala and its technology stack and an introduction is possibly needed.&lt;/p&gt;&#xA;&lt;p style=&#34;text-align: center;&#34;&gt;&lt;img src=&#34;https://ivanyu.me/images/scala-spiral.png&#34; alt=&#34;Scala logo&#34; title=&#34;Scala logo&#34; /&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&#34;http://www.scala-lang.org/&#34;&gt;Scala&lt;/a&gt; is a general purpose programming language created by &lt;a href=&#34;https://en.wikipedia.org/wiki/Martin_Odersky&#34;&gt;Martin Odersky&lt;/a&gt; more than ten years ago. It compiles into JVM byte code and interoperable (both direction) with Java (including mixed compilation), which gives Scala an ability to use all this enormous amount of code created for JVM. The interesting property and also one of the strongest selling points of the language is fusion of object-oriented and functional programming paradigms.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Creating a simple parser with ANTLR</title>
      <link>https://ivanyu.me/blog/2014/09/13/creating-a-simple-parser-with-antlr/</link>
      <pubDate>Sat, 13 Sep 2014 11:42:00 +0300</pubDate>
      <guid>https://ivanyu.me/blog/2014/09/13/creating-a-simple-parser-with-antlr/</guid>
      <description>&lt;p&gt;Recently, I&amp;rsquo;ve faced a task of developing a tool which allows the application to have base of (not very complex) logical rules. There were three demands:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The rules were to be written by non-programmers, so using of the languages which the program is written in (Java/Scala), wasn’t very good.&lt;/li&gt;&#xA;&lt;li&gt;The rule base should be changeable without redeployment of the application, ideally, should be stored in a database.&lt;/li&gt;&#xA;&lt;li&gt;We should have control on compilation and error emission.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;The first and the second demand could be met by developing some kind of Scala- or Groovy-based DSL, extremely simple. But I’ve come with several arguments against:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The third requirement might be hard to meet.&lt;/li&gt;&#xA;&lt;li&gt;The rules are quite simple, so embedding an interpreter of a general-purpose language might be overkill.&lt;/li&gt;&#xA;&lt;li&gt;The language which rules consumer is written in might be changed (from Java/Scala to Python e.g.)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;So, I&amp;rsquo;ve decided to write a very simple rule parser/compiler. After I&amp;rsquo;d created a prototype I decided to write this post, hope it&amp;rsquo;ll be useful. I say in advance that you can see the code adapted for this post in &lt;a href=&#34;https://github.com/ivanyu/logical-rules-parser-antlr&#34;&gt;this repository&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>GNU Parallel</title>
      <link>https://ivanyu.me/blog/2013/12/01/parallel/</link>
      <pubDate>Sun, 01 Dec 2013 18:43:00 +0300</pubDate>
      <guid>https://ivanyu.me/blog/2013/12/01/parallel/</guid>
      <description>&lt;p&gt;How much CPU cores does your computer have? 2-8, I think. It’s very time to use them all, isn’t it? But there are plenty of Unix utils such as &lt;code&gt;grep&lt;/code&gt;, &lt;code&gt;find&lt;/code&gt;, &lt;code&gt;wc&lt;/code&gt; etc., which have no idea about parallel data processing. They can’t split their input into 8 pieces and spawn the corresponding number of threads or processes to process it using all the power of your modern CPU.&lt;/p&gt;&#xA;&lt;p&gt;Definitely, this problem is quite interesting and practical to rest unsolved. According to the Unix philosophy, 1) it is good for programs to do one thing well; 2) it is a good idea to combine simple programs to do complex things. &lt;code&gt;grep&lt;/code&gt; do pattern matching well. How about parallelization?&lt;/p&gt;&#xA;&lt;p&gt;There is an utility know as &lt;a href=&#34;http://www.gnu.org/software/parallel/&#34;&gt;GNU Parallel&lt;/a&gt; which main purpose is to execute arbitrary jobs in parallel on one or &lt;em&gt;even multiple&lt;/em&gt; machines. The program is quite complex and multifunctional, look at &lt;a href=&#34;https://www.gnu.org/software/parallel/man.html&#34;&gt;man&lt;/a&gt; and &lt;a href=&#34;http://www.gnu.org/software/parallel/parallel_tutorial.html&#34;&gt;tutorial&lt;/a&gt;. Here, I want just to give a little flavor of it.&lt;/p&gt;&#xA;&lt;p style=&#34;text-align: center;&#34;&gt;&lt;img src=&#34;https://ivanyu.me/images/gnu-parallel.png&#34; alt=&#34;GNU Parallel&#34; title=&#34;GNU Parallel&#34; /&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Finding a cycle in a linked list</title>
      <link>https://ivanyu.me/blog/2013/11/24/finding-a-cycle-in-a-linked-list/</link>
      <pubDate>Sun, 24 Nov 2013 18:34:00 +0300</pubDate>
      <guid>https://ivanyu.me/blog/2013/11/24/finding-a-cycle-in-a-linked-list/</guid>
      <description>&lt;p&gt;There is a popular task at software developer job interviews: &lt;em&gt;having a singly linked list, write a piece of code which tells if the list has a cycle&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;p&gt;In a &lt;a href=&#34;https://en.wikipedia.org/wiki/Linked_list&#34;&gt;linked list&lt;/a&gt;, each element is a structure which contains the value of an element and the link to the next element. The next-link of the last element has a special value which marks the end (usually, &lt;code&gt;null&lt;/code&gt;). If a list has a cycle, the last element points to some element inside the list.&lt;/p&gt;&#xA;&lt;p style=&#34;text-align: center;&#34;&gt;&lt;img src=&#34;https://ivanyu.me/images/linked_list_types.png&#34; alt=&#34;Linked list types&#34; title=&#34;Linked list types&#34; /&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Z algorithm</title>
      <link>https://ivanyu.me/blog/2013/10/15/z-algorithm/</link>
      <pubDate>Tue, 15 Oct 2013 20:35:00 +0300</pubDate>
      <guid>https://ivanyu.me/blog/2013/10/15/z-algorithm/</guid>
      <description>&lt;style&gt;&#xA;table.ztable {&#xA;  cellspacing: 0px;&#xA;  cellpadding: 0px;&#xA;  border-collapse: collapse;&#xA;  border: 0px solid black;&#xA;  text-align: center;&#xA;  line-height: normal;&#xA;  table-layout: fixed;&#xA;  width:  1px;&#xA;  margin-bottom: 5px;&#xA;&#xA;  font-family: Consolas,Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace !important;&#xA;}&#xA;&#xA;table.ztable-pointers {&#xA;  border: 1px dotted black;&#xA;}&#xA;&#xA;table.ztable tr:nth-of-type(even) {&#xA;&#x9;background: #ffffff;&#xA;}&#xA;&#xA;td.ztable {&#xA;  text-align: center;&#xA;  border: 1px solid black;&#xA;  margin: 2pt 10pt;&#xA;  width: 1.9em;&#xA;  font-size: 87%;&#xA;  padding-bottom: 0.1em;&#xA;  padding-left: 0.1em;&#xA;  padding-right: 0.1em;&#xA;  padding-top: 0.1em;&#xA;}&#xA;&#xA;td.ztable-rowhead {&#xA;  text-align: left;&#xA;  padding: 2pt;&#xA;  width: 5.8em;&#xA;}&#xA;&#xA;td.ztable-zbox {&#xA;  background-color: #c6d9f1;&#xA;}&#xA;&#xA;td.ztable-mis {&#xA;  background-color: #FF5B61;&#xA;}&#xA;&#xA;td.ztable-match {&#xA;  background-color: #9FFF72;&#xA;}&#xA;&#xA;td.ztable-pointer {&#xA;  font-family: monospace;&#xA;  border: 0px solid black;&#xA;  padding-bottom: 0px;&#xA;  padding-top: 0px;&#xA;}&#xA;&lt;/style&gt;&#xA;&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;&#xA;&lt;p&gt;There are some algorithms of exact substring searching (e.g. &lt;a href=&#34;https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm&#34;&gt;&lt;dfn&gt;Knuth-Morris-Pratt&lt;/dfn&gt;&lt;/a&gt;, &lt;a href=&#34;https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string_search_algorithm&#34;&gt;&lt;dfn&gt;Boyer-Moore&lt;/dfn&gt;&lt;/a&gt; etc.) I want to explain one of them which is called &lt;strong&gt;Z algorithm&lt;/strong&gt; in some sources.&lt;/p&gt;&#xA;&lt;h2 id=&#34;z-boxes-and-z-values&#34;&gt;Z-boxes and Z-values&lt;/h2&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s consider the concept of &lt;dfn&gt;Z-box&lt;/dfn&gt;. Take the string &lt;code&gt;S = &amp;ldquo;abcxxxabyyy&amp;rdquo;&lt;/code&gt;. We have an internal part &lt;code&gt;&amp;ldquo;ab&amp;rdquo;&lt;/code&gt; in the string which repeats its prefix. The internal &lt;code&gt;&amp;ldquo;ab&amp;rdquo;&lt;/code&gt; is a &lt;strong&gt;Z-box&lt;/strong&gt;. It has the beginning at the position with index 6 and the end in 7 (0-based). Z-boxes are substrings which match string prefixes with the same length. For the Z-box, let&amp;rsquo;s call the corresponding prefix &lt;dfn&gt;the prototype&lt;/dfn&gt; (it&amp;rsquo;s my term but I think it&amp;rsquo;s OK to use it.)&lt;/p&gt;&#xA;&lt;p style=&#34;text-align: center;&#34;&gt;&lt;img src=&#34;https://ivanyu.me/images/zalg1.png&#34; alt=&#34;Z algorithm&#34; title=&#34;Z algorithm&#34; /&gt;&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
