Sponsored Content
Top Forums Shell Programming and Scripting Java - Arrays.binarySearch function equivalent in awk Post 302853065 by Akshay Hegde on Friday 13th of September 2013 05:15:05 AM
Old 09-13-2013
Java - Arrays.binarySearch function equivalent in awk

Hi all

Does anyone know Java-Arrays.binarySearch function equivalent in awk
I tried like this but it's not correct one,it just returns array index if and only when searched value available in array, for some reason if searched value not found then I want to return upper nearest neighbour index. please let me know if anyone have better idea

Code:
function Arrays_binarySearch(arr,val){
                    
                    for(b in arr){
                    if(arr[b]==val)
                             return b
                             break
                             }    
                    
                     }

here is link to example in java

Java.util.Arrays.binarySearch(int[] a, int key) Method Example

please someone help me..

Last edited by Akshay Hegde; 09-13-2013 at 12:49 PM..
 

10 More Discussions You Might Find Interesting

1. Linux

Equivalent function of [ kbhit() ] In TURBO C

ANy one knows equivalent function of which in Turbo C. I want to Execute Certain loop until any key is pressed. i.e while(!kbhit) { ---------- ---------- } This code work fine in DOS but NOt in LINUX i try to use but not getting the expected result ... (0 Replies)
Discussion started by: niravuchat
0 Replies

2. HP-UX

create thread C with JNI function with JAVA

Hello, J create a thread C with a JNI function via JAVA. J have the following message (but not in each time): Someone has an idea ? Thank. Unexpected Signal : 4 occurred at PC=0x78C103E0 Function= Library=(N/A) NOTE: We are unable to locate the function name... (0 Replies)
Discussion started by: AUBERT
0 Replies

3. Shell Programming and Scripting

shell: creating different arrays based on function argument

hi, I was wondering if there was a good way to create an array within a function, where the name is based on a passed argument? I tried this: _____________________________ func(){ #take in 1st arg as the arrayname arrayName=$1 let i=0 while read line do arrayName=${line} let i+=1... (5 Replies)
Discussion started by: nix21
5 Replies

4. Programming

equivalent function for wherey( ) ??

what is the equivalent function for wherey( ) ?? That is to return the current column position? (2 Replies)
Discussion started by: rockgal
2 Replies

5. Shell Programming and Scripting

Bash equivalent of perl's pack function ?

Is there an equivalent of perl's pack function in bash ? Or in other words, how can I achieve the same thing in bash ? Much appreciated. (1 Reply)
Discussion started by: NewDeb
1 Replies

6. Shell Programming and Scripting

shell script equivalent for tcl function

Hello, I need experts help in converting the below tcl function to korn shell function equivalent. proc lsNetMaskToBits {mask} { set dw ; # Top N bits set set dw 0x ; # Make sure it's hexadecimal, else XOR fails. puts "lsNetMaskToBits dw $dw" set dw ; # Complement => low 32-N bits... (1 Reply)
Discussion started by: JackMelson
1 Replies

7. Programming

Equivalent function for matlab on scilab

Hello everyone, i need help with this , i need the equivalent matlab funtion tf(x,y) in scilab and what do u recommend best from those three for a linux user (i need it for Control theory): 1-matlab 2-Scilab 3-Octave thank you for your time (0 Replies)
Discussion started by: abu_malek
0 Replies

8. Shell Programming and Scripting

Recursive function and arrays

I have the following function in a bash script that fails to return the sorted array. I think the problem lies in the recursion not correctly passing the arrays, but I can't tell what I'm doing wrong. Anyone see the problem? function quicksort () { local array=( `echo "$1"` ) local... (7 Replies)
Discussion started by: tkg
7 Replies

9. Programming

STL algorithm merge() function to concatenate char arrays

When the STL generic algorithm's merge() function is used to merge two char arrays, the output is not as expected. Below is the program I tried with. #include <iostream> #include <algorithm> #include <cstring> #include <deque> #include <iterator> using namespace std; int main() { ... (3 Replies)
Discussion started by: royalibrahim
3 Replies

10. UNIX for Dummies Questions & Answers

Shell equivalent of matlab fwrite function

I have some matlab code that sends the serial port elements of an array using matlab's fwrite function, e.g.: fwrite(s, , 'uchar'); What would be a unix shell equivalent? E.g., after successfully accessing the port using instructions here: Simple terminal serial port program for Linux/MacOSX... (3 Replies)
Discussion started by: darwin_886
3 Replies
COLLATOR_ASORT(3)							 1							 COLLATOR_ASORT(3)

Collator::asort - Sort array maintaining index association

       Object oriented style

SYNOPSIS
public bool Collator::asort (array &$arr, [int $sort_flag]) DESCRIPTION
Procedural style bool collator_asort (Collator $coll, array &$arr, [int $sort_flag]) This function sorts an array such that array indices maintain their correlation with the array elements they are associated with. This is used mainly when sorting associative arrays where the actual element order is significant. Array elements will have sort order according to current locale rules. Equivalent to standard PHP asort(3). PARAMETERS
o $coll -Collator object. o $arr -Array of strings to sort. o $sort_flag - Optional sorting type, one of the following: o Collator::SORT_REGULAR - compare items normally (don't change types) o Collator::SORT_NUMERIC - compare items numerically o Collator::SORT_STRING - compare items as strings Default $sort_flag value is Collator::SORT_REGULAR. It is also used if an invalid $sort_flag value has been specified. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 collator_asort(3)example <?php $coll = collator_create( 'en_US' ); $arr = array( 'a' => '100', 'b' => '50', 'c' => '7' ); collator_asort( $coll, $arr, Collator::SORT_NUMERIC ); var_export( $arr ); collator_asort( $coll, $arr, Collator::SORT_STRING ); var_export( $arr ); ?> The above example will output: array ( 'c' => '7', 'b' => '50', 'a' => '100', )array ( 'a' => '100', 'b' => '50', 'c' => '7', ) SEE ALSO
Collator constants, collator_sort(3), collator_sort_with_sort_keys(3). PHP Documentation Group COLLATOR_ASORT(3)
All times are GMT -4. The time now is 12:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy