zoukankan      html  css  js  c++  java
  • Stable Minimum Storage Merging by Symmetric Comparisons Pok-Son Kim1? and Arne Kutzner2

    Stable Minimum Storage Merging by Symmetric Comparisons Pok-Son Kim1? and Arne Kutzner2

    http://itbe.hanyang.ac.kr/ak/papers/esa2004.pdf

    // symMerge merges the two sorted subsequences data[a:m] and data[m:b] using
    // the SymMerge algorithm from Pok-Son Kim and Arne Kutzner, "Stable Minimum
    // Storage Merging by Symmetric Comparisons", in Susanne Albers and Tomasz
    // Radzik, editors, Algorithms - ESA 2004, volume 3221 of Lecture Notes in
    // Computer Science, pages 714-723. Springer, 2004.
    //
    // Let M = m-a and N = b-n. Wolog M < N.
    // The recursion depth is bound by ceil(log(N+M)).
    // The algorithm needs O(M*log(N/M + 1)) calls to data.Less.
    // The algorithm needs O((M+N)*log(M)) calls to data.Swap.
    //
    // The paper gives O((M+N)*log(M)) as the number of assignments assuming a
    // rotation algorithm which uses O(M+N+gcd(M+N)) assignments. The argumentation
    // in the paper carries through for Swap operations, especially as the block
    // swapping rotate uses only O(M+N) Swaps.
    //
    // symMerge assumes non-degenerate arguments: a < m && m < b.
    // Having the caller check this condition eliminates many leaf recursion calls,
    // which improves performance.
    func symMerge(data Interface, a, m, b int) {
    // Avoid unnecessary recursions of symMerge
    // by direct insertion of data[a] into data[m:b]
    // if data[a:m] only contains one element.
    if m-a == 1 {
    // Use binary search to find the lowest index i
    // such that data[i] >= data[a] for m <= i < b.
    // Exit the search loop with i == b in case no such index exists.
    i := m
    j := b
    for i < j {
    h := int(uint(i+j) >> 1)
    if data.Less(h, a) {
    i = h + 1
    } else {
    j = h
    }
    }
    // Swap values until data[a] reaches the position before i.
    for k := a; k < i-1; k++ {
    data.Swap(k, k+1)
    }
    return
    }

    // Avoid unnecessary recursions of symMerge
    // by direct insertion of data[m] into data[a:m]
    // if data[m:b] only contains one element.
    if b-m == 1 {
    // Use binary search to find the lowest index i
    // such that data[i] > data[m] for a <= i < m.
    // Exit the search loop with i == m in case no such index exists.
    i := a
    j := m
    for i < j {
    h := int(uint(i+j) >> 1)
    if !data.Less(m, h) {
    i = h + 1
    } else {
    j = h
    }
    }
    // Swap values until data[m] reaches the position i.
    for k := m; k > i; k-- {
    data.Swap(k, k-1)
    }
    return
    }

    mid := int(uint(a+b) >> 1)
    n := mid + m
    var start, r int
    if m > mid {
    start = n - b
    r = mid
    } else {
    start = a
    r = m
    }
    p := n - 1

    for start < r {
    c := int(uint(start+r) >> 1)
    if !data.Less(p-c, c) {
    start = c + 1
    } else {
    r = c
    }
    }

    end := n - start
    if start < m && m < end {
    rotate(data, start, m, end)
    }
    if a < start && start < mid {
    symMerge(data, a, start, mid)
    }
    if mid < end && end < b {
    symMerge(data, mid, end, b)
    }
    }
  • 相关阅读:
    POJ 1811 Prime Test 素性测试 分解素因子
    sysbench的安装与使用
    电脑中已有VS2005和VS2010安装.NET3.5失败的解决方案
    I.MX6 show battery states in commandLine
    RPi 2B Raspbian system install
    I.MX6 bq27441 driver porting
    I.MX6 隐藏电池图标
    I.MX6 Power off register hacking
    I.MX6 Goodix GT9xx touchscreen driver porting
    busybox filesystem httpd php-5.5.31 sqlite3 webserver
  • 原文地址:https://www.cnblogs.com/rsapaper/p/14921495.html
Copyright © 2011-2022 走看看