<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Search on Nalar</title>
    <link>https://nalar.dev/tags/search/</link>
    <description>Recent content in Search on Nalar</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 10 Sep 2026 00:00:00 +0700</lastBuildDate>
    <atom:link href="https://nalar.dev/tags/search/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Find Values and Insertion Points with slices.BinarySearch</title>
      <link>https://nalar.dev/find-values-and-insertion-points-with-slices-binarysearch/</link>
      <pubDate>Thu, 10 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/find-values-and-insertion-points-with-slices-binarysearch/</guid>
      <description>&lt;p&gt;When a Go slice is already sorted, scanning it from the beginning to find one value throws away useful information. &lt;code&gt;slices.BinarySearch&lt;/code&gt; uses that ordering directly. It returns both an index and a &lt;code&gt;found&lt;/code&gt; flag, and the index remains useful even when the target isn&amp;rsquo;t present.&lt;/p&gt;&#xA;&lt;p&gt;That second behavior is easy to overlook. &lt;code&gt;slices.BinarySearch&lt;/code&gt; isn&amp;rsquo;t only a membership check; it also tells you where a missing value belongs if you want to preserve the slice&amp;rsquo;s sort order.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Search Go Struct Slices with slices.BinarySearchFunc</title>
      <link>https://nalar.dev/search-go-struct-slices-with-slices-binarysearchfunc/</link>
      <pubDate>Thu, 10 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/search-go-struct-slices-with-slices-binarysearchfunc/</guid>
      <description>&lt;p&gt;A slice of structs can be sorted by an ID, timestamp, or other field even though the struct itself has no built-in ordering. When you need repeated lookups in that sorted data, &lt;code&gt;slices.BinarySearchFunc&lt;/code&gt; lets the search use the same ordering without building a separate index.&lt;/p&gt;&#xA;&lt;p&gt;The comparator is the part that deserves attention. It doesn&amp;rsquo;t compare two slice elements. It compares one element from the slice with the search target, and its ordering must agree with the way the slice is sorted.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
