org.jruby.util.Qsort.sort()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(3.3k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中org.jruby.util.Qsort.sort方法的一些代码示例,展示了Qsort.sort的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Qsort.sort方法的具体详情如下:
包路径:org.jruby.util.Qsort
类名称:Qsort
方法名:sort

Qsort.sort介绍

暂无

代码示例

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

private IRubyObject sortInternal(final ThreadContext context, final Block block) {
  IRubyObject[] newValues = new IRubyObject[realLength];
  int length = realLength;
  safeArrayCopy(values, begin, newValues, 0, length);
  Qsort.sort(newValues, 0, length, new Comparator() {
    public int compare(Object o1, Object o2) {
      IRubyObject obj1 = (IRubyObject) o1;
      IRubyObject obj2 = (IRubyObject) o2;
      IRubyObject ret = block.yieldArray(context, getRuntime().newArray(obj1, obj2), null, null);
      //TODO: ary_sort_check should be done here
      return RubyComparable.cmpint(context, ret, obj1, obj2);
    }
  });
  
  values = newValues;
  begin = 0;
  realLength = length;
  return this;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

private IRubyObject sortInternal(final ThreadContext context, final Block block) {
  IRubyObject[] newValues = new IRubyObject[realLength];
  int length = realLength;
  safeArrayCopy(values, begin, newValues, 0, length);
  Qsort.sort(newValues, 0, length, new Comparator() {
    public int compare(Object o1, Object o2) {
      IRubyObject obj1 = (IRubyObject) o1;
      IRubyObject obj2 = (IRubyObject) o2;
      IRubyObject ret = block.yieldArray(context, getRuntime().newArray(obj1, obj2), null, null);
      //TODO: ary_sort_check should be done here
      return RubyComparable.cmpint(context, ret, obj1, obj2);
    }
  });
  
  values = newValues;
  begin = 0;
  realLength = length;
  return this;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

private IRubyObject sortInternal(final ThreadContext context, boolean honorOverride) {
  // One check per specialized fast-path to make the check invariant.
  final boolean fixnumBypass = !honorOverride || context.runtime.newFixnum(0).isBuiltin("<=>");
  final boolean stringBypass = !honorOverride || context.runtime.newString("").isBuiltin("<=>");
  try {
    Qsort.sort(values, begin, begin + realLength, new Comparator() {
      public int compare(Object o1, Object o2) {
        if (fixnumBypass && o1 instanceof RubyFixnum && o2 instanceof RubyFixnum) {
          return compareFixnums((RubyFixnum) o1, (RubyFixnum) o2);
        }
        if (stringBypass && o1 instanceof RubyString && o2 instanceof RubyString) {
          return ((RubyString) o1).op_cmp((RubyString) o2);
        }
        return compareOthers(context, (IRubyObject)o1, (IRubyObject)o2);
      }
    });
  } catch (ArrayIndexOutOfBoundsException aioob) {
    concurrentModification();
  }
  return this;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

private IRubyObject sortInternal(final ThreadContext context, boolean honorOverride) {
  // One check per specialized fast-path to make the check invariant.
  final boolean fixnumBypass = !honorOverride || context.runtime.newFixnum(0).isBuiltin("<=>");
  final boolean stringBypass = !honorOverride || context.runtime.newString("").isBuiltin("<=>");
  try {
    Qsort.sort(values, begin, begin + realLength, new Comparator() {
      public int compare(Object o1, Object o2) {
        if (fixnumBypass && o1 instanceof RubyFixnum && o2 instanceof RubyFixnum) {
          return compareFixnums((RubyFixnum) o1, (RubyFixnum) o2);
        }
        if (stringBypass && o1 instanceof RubyString && o2 instanceof RubyString) {
          return ((RubyString) o1).op_cmp((RubyString) o2);
        }
        return compareOthers(context, (IRubyObject)o1, (IRubyObject)o2);
      }
    });
  } catch (ArrayIndexOutOfBoundsException aioob) {
    concurrentModification();
  }
  return this;
}

相关文章